Update of /cvsroot/freenet/freenet/src/freenet/fs/dir
In directory sc8-pr-cvs1:/tmp/cvs-serv13360

Modified Files:
        FileNumber.java 
Log Message:
Minor optimization and removal of unnecessary complexity
in calculation of the int hashCode:  hashCode is calculated
once when object is created.  Also the field containing
the long hash code is now called longHashCode.

This started with just correcting the comment here:

    long x = ((long)hashCode) & 0xFFFFFFFFL; // sixteen ones in binary

but got out of hand.  The masking operation is completely
unnecessary.  If there were going to be an exception in
the cast due to loss of precision, it would still occur
with the masking in place, because of the change in
sign.  

 JLS section 5.1.3:  A narrowing conversion of a signed
 integer to an integral type T simply discards all but the n
 lowest order bits, where n is the number of bits used to
 represent type T.  In addition to a possible loss of
 information about the magnitude of the numeric value, this
 may cause the sign of the resulting value to differ from
 the sign of the input value.
 (longHashCode unsigned shift right 32) XOR longHashCode


Index: FileNumber.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/fs/dir/FileNumber.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FileNumber.java     9 Feb 2003 03:51:07 -0000       1.6
+++ FileNumber.java     12 Oct 2003 01:46:28 -0000      1.7
@@ -15,8 +15,8 @@
     
     final int dirID;
     final byte[] key;
-
-    final long hashCode;
+    final int hashCode;
+    final long longHashCode;
 
     /**
      * Wrap a FileNumber as a FileNumber (with a different dirID)
@@ -26,7 +26,8 @@
     FileNumber(int dirID, FileNumber fn) {
         this.dirID = dirID;
         this.key = fn.key;
-        hashCode = fn.hashCode;
+        longHashCode = fn.longHashCode;
+       hashCode = fn.hashCode;
     }
     
     /** 
@@ -37,7 +38,9 @@
     FileNumber(int dirID, byte[] key) {
         this.dirID = dirID;
         this.key = key;
-        hashCode = Fields.longHashCode(key);
+       longHashCode = Fields.longHashCode(key);
+
+       hashCode = (int)((longHashCode >>> 32) ^ longHashCode);
     }
 
     /**
@@ -114,13 +117,11 @@
     }
 
     public final long longHashCode() {
-       return hashCode;
+       return longHashCode;
     }
     
     public final int hashCode() {
-       long x = ((long)hashCode) & 0xFFFFFFFFL; // sixteen ones in binary
-       long y = hashCode >>> 32;
-       return (int)(x ^ y);
+       return hashCode;
     }
     
     /** get directory ID

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to