Author: markt Date: Mon Jan 15 22:06:01 2018 New Revision: 1821198 URL: http://svn.apache.org/viewvc?rev=1821198&view=rev Log: Pull up and align start (a.k.a. offset), end and hashcode
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/AbstractChunk.java tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/AbstractChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/AbstractChunk.java?rev=1821198&r1=1821197&r2=1821198&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/AbstractChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/AbstractChunk.java Mon Jan 15 22:06:01 2018 @@ -25,4 +25,77 @@ public abstract class AbstractChunk impl private static final long serialVersionUID = 1L; + + private int hashCode = 0; + protected boolean hasHashCode = false; + + protected int start; + protected int end; + + + /** + * @return the start position of the data in the buffer + */ + public int getStart() { + return start; + } + + + public int getEnd() { + return end; + } + + + public void setEnd(int i) { + end = i; + } + + + /** + * @return the length of the data in the buffer + */ + public int getLength() { + return end - start; + } + + + // TODO: Deprecate offset and use start + + public int getOffset() { + return start; + } + + + public void setOffset(int off) { + if (end < off) { + end = off; + } + start = off; + } + + + @Override + public int hashCode() { + if (hasHashCode) { + return hashCode; + } + int code = 0; + + code = hash(); + hashCode = code; + hasHashCode = true; + return code; + } + + + public int hash() { + int code = 0; + for (int i = start; i < end; i++) { + code = code * 37 + getBufferElement(i); + } + return code; + } + + + protected abstract int getBufferElement(int index); } Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1821198&r1=1821197&r2=1821198&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Mon Jan 15 22:06:01 2018 @@ -122,16 +122,9 @@ public final class ByteChunk extends Abs */ public static final Charset DEFAULT_CHARSET = StandardCharsets.ISO_8859_1; - private int hashCode = 0; - // did we compute the hashcode ? - private boolean hasHashCode = false; - // byte[] private byte[] buff; - private int start = 0; - private int end; - private transient Charset charset; private boolean isSet = false; // XXX @@ -252,36 +245,6 @@ public final class ByteChunk extends Abs /** - * @return the start offset of the bytes. For output this is the end of the - * buffer. - */ - public int getStart() { - return start; - } - - - public int getOffset() { - return start; - } - - - public void setOffset(int off) { - if (end < off) { - end = off; - } - start = off; - } - - - /** - * @return the length of the bytes. - */ - public int getLength() { - return end - start; - } - - - /** * Maximum amount of data in this buffer. If -1 or not set, the buffer will * grow indefinitely. Can be smaller than the current buffer size ( which * will not shrink ). When the limit is reached, the buffer will be flushed @@ -321,16 +284,6 @@ public final class ByteChunk extends Abs } - public int getEnd() { - return end; - } - - - public void setEnd(int i) { - end = i; - } - - // -------------------- Adding data to the buffer -------------------- public void append(byte b) throws IOException { makeSpace(1); @@ -803,36 +756,9 @@ public final class ByteChunk extends Abs } - // -------------------- Hash code -------------------- - @Override - public int hashCode() { - if (hasHashCode) { - return hashCode; - } - int code = 0; - - code = hash(); - hashCode = code; - hasHashCode = true; - return code; - } - - - // normal hash. - public int hash() { - return hashBytes(buff, start, end - start); - } - - - private static int hashBytes(byte buff[], int start, int bytesLen) { - int max = start + bytesLen; - byte bb[] = buff; - int code = 0; - for (int i = start; i < max; i++) { - code = code * 37 + bb[i]; - } - return code; + protected int getBufferElement(int index) { + return buff[index]; } Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java?rev=1821198&r1=1821197&r2=1821198&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Mon Jan 15 22:06:01 2018 @@ -65,16 +65,9 @@ public final class CharChunk extends Abs // -------------------- - private int hashCode = 0; - // did we compute the hashcode ? - private boolean hasHashCode = false; - // char[] private char buff[]; - private int start; - private int end; - private boolean isSet = false; // XXX // -1: grow indefinitely @@ -207,46 +200,6 @@ public final class CharChunk extends Abs } - /** - * @return the start offset of the chars. For output this is the end of the - * buffer. - */ - public int getStart() { - return start; - } - - - public int getOffset() { - return start; - } - - - /** - * @param off The offset - */ - public void setOffset(int off) { - start = off; - } - - - /** - * @return the length of the bytes. - */ - public int getLength() { - return end - start; - } - - - public int getEnd() { - return end; - } - - - public void setEnd(int i) { - end = i; - } - - // -------------------- Adding data -------------------- public void append(char b) throws IOException { @@ -647,29 +600,9 @@ public final class CharChunk extends Abs } - // -------------------- Hash code -------------------- - @Override - public int hashCode() { - if (hasHashCode) { - return hashCode; - } - int code = 0; - - code = hash(); - hashCode = code; - hasHashCode = true; - return code; - } - - - // normal hash. - public int hash() { - int code = 0; - for (int i = start; i < start + end - start; i++) { - code = code * 37 + buff[i]; - } - return code; + protected int getBufferElement(int index) { + return buff[index]; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org