db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Pendleton (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6885) Remove ReuseFactory
Date Sun, 24 Apr 2016 19:41:12 GMT

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

Bryan Pendleton commented on DERBY-6885:

Thanks for the cleanup. I desk-checked and proofread the code, and it all looks great.


If you have a minute, perhaps you could elaborate on why, in this part of the change,
you were able to change the variable "success" from Boolean to boolean, but the
PrivilegedAction itself is still a PrivilegedAction<Boolean>? Is it because boolean
a primitive, not a "true" type, while Boolean is a true type?

-        Boolean success = AccessController.doPrivileged(
-                new PrivilegedAction<Boolean>() {
-                    public Boolean run() {
-                        return ReuseFactory.getBoolean(FileUtil.copyFile(
-                                dataFactory.getStorageFactory(), from, to));
-                    }
-                });
-        if (!success.booleanValue()) {
+        PrivilegedAction<Boolean> pa = () ->
+                FileUtil.copyFile(dataFactory.getStorageFactory(), from, to);
+        boolean success = AccessController.doPrivileged(pa);
+        if (!success) {

I guess that the compiler is seeing an assignment
    boolean = Boolean
in the call to doPrivileged(), and is automatically generating a call to booleanValue()
to extract the boolean value from the Boolean object into the boolean primitive?

I suppose this is why we can't remove the "success" variable entirely, in favor of:

+        PrivilegedAction<Boolean> pa = () ->
+                FileUtil.copyFile(dataFactory.getStorageFactory(), from, to);
+        if (! AccessController.doPrivileged(pa) ) {

because a Boolean can't be simply tested like that in the "if" statement,
while a boolean can?

> Remove ReuseFactory
> -------------------
>                 Key: DERBY-6885
>                 URL: https://issues.apache.org/jira/browse/DERBY-6885
>             Project: Derby
>          Issue Type: Improvement
>          Components: Services
>    Affects Versions:
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: d6885.diff
> ReuseFactory used to help reduce object allocations when converting numbers/booleans
from primitive types to object types. After DERBY-2383 and DERBY-6230, the ReuseFactory methods
are just wrappers around standard library methods such as Integer.valueOf() and Long.valueOf().
> Callers could just as easily call the corresponding valueOf() method directly, or rely
on auto-boxing. Both ways use the same cache as ReuseFactory currently does, so ReuseFactory
has no purpose anymore.
> One exception: ReuseFactory.getZeroLenByteArray() is still used and provides value, as
it avoids the allocation cost when an empty byte array is needed. The ArrayUtil class is probably
just as good a home for it, so I propose we move it there and remove the ReuseFactory class.

This message was sent by Atlassian JIRA

View raw message