timboudreau commented on pull request #2232:
URL: https://github.com/apache/netbeans/pull/2232#issuecomment-656799249


   It's possible to get it down to a single field worth of overhead:
   
   ```java
       @SuppressWarnings("LeakingThisInConstructor")
       public ProxyLookup(Controller controller) {
           data = ImmutableInternalData.EMPTY.setLookupsNoFire(
                   controller.setProxyLookup(this), true);
       }
   
   ...
   
       public static final class Controller {
   
           private BiConsumer<? super Executor, ? super Lookup[]> consumer;
   
           public Controller(Lookup... lookups) {
               consumer = new InitialConsumer(lookups);
           }
   
           public Controller() {
               consumer = new InitialConsumer();
           }
   
           public synchronized void setLookups(Executor exe, Lookup... lookups) 
{
               consumer.accept(exe, lookups);
           }
   
           public void setLookups(Lookup... lookups) {
               setLookups(null, lookups);
           }
   
           synchronized Lookup[] setProxyLookup(ProxyLookup lkp) {
               if (!(this.consumer instanceof InitialConsumer)) {
                   throw new IllegalStateException("Attempting to use "
                           + "ProxyLookup.Controller for more than one "
                           + "ProxyLookup is illegal");
               }
               Lookup[] result = ((InitialConsumer) consumer).lookups;
               this.consumer = lkp::setLookups;
               return result;
           }
           
           private static class InitialConsumer implements BiConsumer<Executor, 
Lookup[]> {
               Lookup[] lookups;
               
               InitialConsumer() {
               }
               
               InitialConsumer(Lookup[] lookups) {
                   this.lookups = lookups;
               }
   
               @Override
               public void accept(Executor ignored, Lookup[] lookups) {
                   this.lookups = Arrays.copyOf(lookups, lookups.length);
               }
           }
       }
   ```
   
   The locking, however, remains.
   
   


----------------------------------------------------------------
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.

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



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

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to