Re: [EGIT PATCH 2/6] Cleanup unboxing/boxing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> wrote:
> These operation are relatively expensive in general so it is good to make them
> visible, but when they are needed a lot we just want to do without explicit conversion
> so we ignore the warning there.
> @@ -207,7 +207,7 @@ public class GitResourceDecorator extends LabelProvider implements
>  					return Boolean.FALSE;
>  				}
>  
> -				return mapped.isResourceChanged(rsrc);
> +				return new Boolean(mapped.isResourceChanged(rsrc));
>  			}
>  			return null; // not mapped
>  		} catch (CoreException e) {

Oooooooow.  That hurts.

Use Boolean.valueOf(boolean) instead of new Boolean.  It recycles
the cached Boolean.TRUE and Boolean.FALSE and thus avoids creating
garbage that the GC needs to reclaim later.

> @@ -358,7 +358,7 @@ public class GitResourceDecorator extends LabelProvider implements
>  		try {
>  			Integer dirty = (Integer) rsrc.getSessionProperty(GITFOLDERDIRTYSTATEPROPERTY);
>  			if (dirty == null) {
> -				rsrc.setSessionProperty(GITFOLDERDIRTYSTATEPROPERTY, flag);
> +				rsrc.setSessionProperty(GITFOLDERDIRTYSTATEPROPERTY, new Integer(flag));
>  				Activator.trace("SETTING:"+rsrc.getFullPath().toOSString()+" => "+flag);
>  				orState(rsrc.getParent(), flag);
>  				Display.getDefault().asyncExec(new Runnable() {

Use Integer.valueOf(int).  Post Java 5 implementations of the J2SE
are required to cache values between -128 and 127 (inclusive).

Actually, when the Java compiler autoboxes values it does so through
these static valueOf methods, which were mostly introduced as part
of the Java 5 API updates.  For small common values its cached and
will thus avoid garbage generation, for less common values it goes
back to allocating the object.

-- 
Shawn.
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux