[jboss-svn-commits] JBL Code SVN: r10871 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Apr 10 19:09:20 EDT 2007


Author: tirelli
Date: 2007-04-10 19:09:20 -0400 (Tue, 10 Apr 2007)
New Revision: 10871

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java
Log:
JBRULES-740: caching hashcode

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java	2007-04-10 22:05:38 UTC (rev 10870)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java	2007-04-10 23:09:20 UTC (rev 10871)
@@ -46,6 +46,8 @@
 
     public static final String DELEGATE_FIELD_NAME = "delegate";
 
+    public static final String HASHCACHE_FIELD_NAME = "__hashCache";
+
     public static Class getProxy(final Class clazz) {
         try {
             if(( clazz.getModifiers() & Modifier.FINAL ) != 0 ) {
@@ -174,6 +176,11 @@
                      className,
                      clazz,
                      fieldTypes );
+        
+        
+        buildField( ShadowProxyFactory.HASHCACHE_FIELD_NAME,
+                	Type.getDescriptor( int.class ),
+                	cw );
 
         buildHashCode( cw,
                        className,
@@ -455,6 +462,14 @@
                            className,
                            fieldName,
                            Type.getDescriptor( fieldType ) );
+        
+        //    this.__hashCache = 0;
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitInsn(Opcodes.ICONST_0);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, 
+        		          className, 
+        		          ShadowProxyFactory.HASHCACHE_FIELD_NAME, 
+        		          Type.getDescriptor( int.class ));
 
         // }
         // return __field;
@@ -579,6 +594,15 @@
                                fieldFlag,
                                Type.BOOLEAN_TYPE.getDescriptor() );
         }
+
+        //    this.__hashCache = 0;
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitInsn(Opcodes.ICONST_0);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, 
+        		          className, 
+        		          ShadowProxyFactory.HASHCACHE_FIELD_NAME, 
+        		          Type.getDescriptor( int.class ));
+        
         final Label l4 = new Label();
         mv.visitLabel( l4 );
         mv.visitInsn( Opcodes.RETURN );
@@ -935,6 +959,9 @@
      *  Sample of generated code for all primitive + object types
      *  
      *  public int hashCode() {
+     *       if( ___hashCache != 0 ) {
+     *           return __hashCache;
+     *       }
      *       final int PRIME = 31;
      *       int result = 1;
      *       result = PRIME * result + (booleanAttr ? 1231 : 1237);
@@ -970,6 +997,27 @@
                                  null );
             mv.visitCode();
 
+            // if( __hashCache != 0 ) {
+            Label ls = new Label();
+            mv.visitLabel(ls);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD, 
+            		          className, 
+            		          ShadowProxyFactory.HASHCACHE_FIELD_NAME, 
+            		          Type.getDescriptor( int.class ));
+            Label afterIfCachedLabel = new Label();
+            mv.visitJumpInsn(Opcodes.IFEQ, afterIfCachedLabel);
+            //     return __hashCache;
+            // }
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD, 
+  		          className, 
+  		          ShadowProxyFactory.HASHCACHE_FIELD_NAME, 
+  		          Type.getDescriptor( int.class ));
+            mv.visitInsn(Opcodes.IRETURN);
+            mv.visitLabel(afterIfCachedLabel);
+            
+            
             // final int PRIME = 31;
             Label l0 = new Label();
             mv.visitLabel( l0 );
@@ -1190,6 +1238,16 @@
                 }
                 mv.visitLabel( goNext );
             }
+            
+            // __hashCache = result;
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitVarInsn(Opcodes.ILOAD, 2);
+            mv.visitFieldInsn(Opcodes.PUTFIELD, 
+                              className, 
+                              ShadowProxyFactory.HASHCACHE_FIELD_NAME, 
+                              Type.getDescriptor( int.class ));
+            
+            // return result;
             mv.visitVarInsn( Opcodes.ILOAD,
                              2 );
             mv.visitInsn( Opcodes.IRETURN );




More information about the jboss-svn-commits mailing list