netudima commented on code in PR #3761:
URL: https://github.com/apache/cassandra/pull/3761#discussion_r1910548979


##########
src/java/org/apache/cassandra/cql3/VariableSpecifications.java:
##########
@@ -56,6 +59,17 @@ public List<ColumnSpecification> getBindVariables()
         return specs;
     }
 
+    public ImmutableList<ColumnSpecification> getImmutableBindVariables()
+    {
+        ImmutableList<ColumnSpecification> result = immutableSpecs;
+        if (result == null) // strong syncrhronization is not needed, it is ok 
if sometimes we create several immutable lists
+        {
+            result = ImmutableList.copyOf(specs);
+            immutableSpecs = result;
+        }
+        return result;

Review Comment:
   immutableSpecs is a volatile variable, in your case we read it 2 times, in 
my one - just once. It is a slightly better from performance point of view + a 
less error prone style when you compare and return the same reference which 
cannot be changed.  It is a kind of typical pattern to deal with volatile 
variables (and sometimes even with plain fields). You can find it quite a lot 
in JDK code, for example:
   ```
   Node<K, V>[] tab = this.table;
   while(true) {
       int n;
       while(tab == null || (n = tab.length) == 0) {
       tab = this.initTable();
   }
   ```
   from: java.util.concurrent.ConcurrentHashMap#putVal



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to