On 2016-10-01 18:54, Martin Buchholz wrote:

On Sat, Oct 1, 2016 at 5:45 AM, Claes Redestad
<claes.redes...@oracle.com <mailto:claes.redes...@oracle.com>> wrote:


    On 2016-10-01 02:41, Martin Buchholz wrote:

        https://bugs.openjdk.java.net/browse/JDK-8167002
        <https://bugs.openjdk.java.net/browse/JDK-8167002>
        
http://cr.openjdk.java.net/~martin/webrevs/openjdk9/xml-id-validation-by-hash/
        
<http://cr.openjdk.java.net/~martin/webrevs/openjdk9/xml-id-validation-by-hash/>


    +1, but I have to ask what the intended benefit of writing:

       ((fIds != null) ? fIds : (fIds = new HashSet<>())).add(name);

    rather than keeping the pre-existing pattern:

       if (fIds == null) fIds = new HashSet<>();
       fIds.add(name);

    If this is about bytecode optimization to help with inlining or such,
    the latter actually generate a more compact method (14 vs 16 bytecodes).


The intent was (by instinct) to not code a re-read of a field, but ...
yeah .... that wasn't achieved.
That could be done correctly using

     public void addId(String name) {
         HashSet<String> x;
         if ((x = fIds) == null) fIds = x = new HashSet<>();
         x.add(name);
     }

but I'll just revert to
         if (fIds == null) fIds = new HashSet<>();
         fIds.add(name);


Ok, thanks for the explanation!

Reply via email to