[ 
https://issues.apache.org/jira/browse/DERBY-5873?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422092#comment-13422092
 ] 

Knut Anders Hatlen commented on DERBY-5873:
-------------------------------------------

In the first patch, I forgot about the BigDecimal and BigInteger classes, which 
are also sub-classes of Number. I see that Java 5 introduced the following 
valueOf() factory methods for BigDecimal that we could use:

- valueOf(double) - replaces the "new BigDecimal(Double.toString(<double>))" 
idiom used to convert a double to BigDecimal without changing the precision

- valueOf(long, int) - could be used to create a BigDecimal value directly 
instead of going via a BigInteger and/or byte[], if the unscaled value is known 
to fit in a long

Will post a followup patch.
                
> Avoid unnecessary allocation of Number instances in client/server
> -----------------------------------------------------------------
>
>                 Key: DERBY-5873
>                 URL: https://issues.apache.org/jira/browse/DERBY-5873
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Client, Network Server
>    Affects Versions: 10.10.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d5873-1a.diff
>
>
> Java 5 introduced some new static factory methods (called valueOf()) in the 
> Number sub-classes, to be used in preference of the constructors unless a 
> fresh instance is required. The valueOf() methods are allowed to cache and 
> reuse objects, possibly reducing the allocation/gc cost and the memory 
> footprint. For example, Integer.valueOf(int) uses a pre-allocated cache for 
> values between -128 and +127 by default (the cache size can be tuned with JVM 
> flags).
> Now that the server and client code is compiled against Java 5 libraries, we 
> should use the valueOf() methods  to get those benefits. Note also that Java 
> 5 auto-boxing of numbers uses these methods implicitly, so in many cases we 
> can just remove the calls to the constructor and the compiler will 
> automatically insert the calls for us.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to