db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r504460 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
Date Wed, 07 Feb 2007 08:39:17 GMT
Author: kahatlen
Date: Wed Feb  7 00:39:16 2007
New Revision: 504460

URL: http://svn.apache.org/viewvc?view=rev&rev=504460
Log:
DERBY-2191: Cleanup of FormatableBitSet

Simplified grow() by removing an unneeded special case.
Added ASSERT(invariantHolds()) to grow() and shrink().

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java?view=diff&rev=504460&r1=504459&r2=504460
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
Wed Feb  7 00:39:16 2007
@@ -291,6 +291,10 @@
 	 */
 	public void grow(int n)
 	{
+		if (SanityManager.DEBUG) {
+			SanityManager.ASSERT(invariantHolds(), "broken invariant");
+		}
+
  		if (n < 0) {
  			throw new IllegalArgumentException("Bit set cannot grow from "+
  											   lengthAsBits+" to "+n+" bits");
@@ -299,37 +303,17 @@
  			return;
  		}
 
-		int delta = n - lengthAsBits;
-		int oldNumBytes = getLengthInBytes();
-
-		/*
-		** If we have enough space in the left over bits,
-		** then all we need to do is change the modulo.
-		*/
-		if ((oldNumBytes != 0) &&
-		    (8 - this.bitsInLastByte) >= delta)
-		{
-			this.bitsInLastByte += delta;
-			lengthAsBits = n;
-			return;
-		}
-
 		int newNumBytes = FormatableBitSet.numBytesFromBits(n);
 
 		// is there enough room in the existing array
-		if (newNumBytes <= value.length) {
-			// ensure the bits are zeroed
-			for (int i = oldNumBytes; i <  newNumBytes; i++)
-				value[i] = 0;
-		} else {
-
-
+		if (newNumBytes > value.length) {
 			/*
 			** We didn't have enough bytes in value, so we need
 			** to create a bigger byte array and use that.
 			*/
 			byte[] newValue = new byte[newNumBytes];
 
+			int oldNumBytes = getLengthInBytes();
 			System.arraycopy(value, 0, newValue, 0, oldNumBytes);
 
 			value = newValue;
@@ -348,6 +332,10 @@
 	 */
 	public void shrink(int n)
 	{
+		if (SanityManager.DEBUG) {
+			SanityManager.ASSERT(invariantHolds(), "broken invariant");
+		}
+
 		if (n < 0 || n > lengthAsBits) {
 			throw new
 				IllegalArgumentException("Bit set cannot shrink from "+



Mime
View raw message