2014-10-01 18:24 GMT+04:00  <ma...@apache.org>:
> Author: markt
> Date: Wed Oct  1 14:24:49 2014
> New Revision: 1628712
>
> URL: http://svn.apache.org/r1628712
> Log:
> boolean[] -> BitSet

Officially, javadoc for BitSet says that the class is not thread-safe
[1] though the actual implementation of get() method as far as I see
is a safe one.

This saves memory for the array from 512 bytes to 16 bytes, but adds
some computations. Given that we have a copy of this array (or bit
set) in each web application, I agree that such memory save is worth
it.

[1] http://docs.oracle.com/javase/8/docs/api/java/util/BitSet.html


By the way, there exists java.math.BigInteger class with its setBit(),
clearBit() and testBit() methods.



> Modified:
>     tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java
>
> Modified: 
> tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java?rev=1628712&r1=1628711&r2=1628712&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java 
> (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java 
> Wed Oct  1 14:24:49 2014
> @@ -18,6 +18,7 @@ package org.apache.tomcat.util.http;
>
>  import java.nio.charset.Charset;
>  import java.nio.charset.StandardCharsets;
> +import java.util.BitSet;
>
>  import org.apache.juli.logging.Log;
>  import org.apache.juli.logging.LogFactory;
> @@ -45,7 +46,7 @@ public final class LegacyCookieProcessor
>              StringManager.getManager("org.apache.tomcat.util.http");
>
>      private static final char[] V0_SEPARATORS = {',', ';', ' ', '\t'};
> -    private static final boolean[] V0_SEPARATOR_FLAGS = new boolean[128];
> +    private static final BitSet V0_SEPARATOR_FLAGS = new BitSet(128);
>
>      // Excludes '/' since configuration controls whether or not to treat '/' 
> as
>      // a separator
> @@ -55,7 +56,7 @@ public final class LegacyCookieProcessor
>
>      static {
>          for (char c : V0_SEPARATORS) {
> -            V0_SEPARATOR_FLAGS[c] = true;
> +            V0_SEPARATOR_FLAGS.set(c);
>          }
>      }
>
> @@ -73,18 +74,20 @@ public final class LegacyCookieProcessor
>                                       // when deprecated code is removed
>      private boolean presserveCookieHeader = 
> CookieSupport.PRESERVE_COOKIE_HEADER;
>
> -    private boolean[] httpSeparatorFlags = new boolean[128];
> +    private BitSet httpSeparatorFlags = new BitSet(128);
>
>
>      public LegacyCookieProcessor() {
> -        // Array elements will default to false
> +        // BitSet elements will default to false
>          for (char c : HTTP_SEPARATORS) {
> -            httpSeparatorFlags[c] = true;
> +            httpSeparatorFlags.set(c);
>          }
>          @SuppressWarnings("deprecation") // Default to 
> STRICT_SERVLET_COMPLIANCE
>                                           // when deprecated code is removed
>          boolean b = CookieSupport.FWD_SLASH_IS_SEPARATOR;
> -        httpSeparatorFlags['/'] = b;
> +        if (b) {
> +            httpSeparatorFlags.set('/');
> +        }
>      }
>
>
> @@ -129,12 +132,16 @@ public final class LegacyCookieProcessor
>
>
>      public boolean getForwardSlashIsSeparator() {
> -        return httpSeparatorFlags['/'];
> +        return httpSeparatorFlags.get('/');
>      }
>
>
>      public void setForwardSlashIsSeparator(boolean forwardSlashIsSeparator) {
> -        httpSeparatorFlags['/'] = forwardSlashIsSeparator;
> +        if (forwardSlashIsSeparator) {
> +            httpSeparatorFlags.set('/');
> +        } else {
> +            httpSeparatorFlags.clear('/');
> +        }
>      }
>
>
> @@ -478,7 +485,7 @@ public final class LegacyCookieProcessor
>              }
>          }
>
> -        return httpSeparatorFlags[c];
> +        return httpSeparatorFlags.get(c);
>      }
>
>
> @@ -494,7 +501,7 @@ public final class LegacyCookieProcessor
>              }
>          }
>
> -        return V0_SEPARATOR_FLAGS[c];
> +        return V0_SEPARATOR_FLAGS.get(c);
>      }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to