[armedbear-cvs] r12279 - trunk/abcl/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sun Nov 15 21:07:30 UTC 2009


Author: ehuelsmann
Date: Sun Nov 15 16:07:24 2009
New Revision: 12279

Log:
Make car()/cdr()/setCar()/setCdr()/EQ() non-virtual,
  dispatching where required on instanceof.

Note: Our findings are that virtual calls are slower than
  instanceof checks (followed by a cast if necessary),
  meaning that for small numbers of instanceof comparisons
  the construct now committed will be faster.

Patch by: vvoutilainen

Modified:
   trunk/abcl/src/org/armedbear/lisp/Cons.java
   trunk/abcl/src/org/armedbear/lisp/LispObject.java
   trunk/abcl/src/org/armedbear/lisp/Nil.java

Modified: trunk/abcl/src/org/armedbear/lisp/Cons.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Cons.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Cons.java	Sun Nov 15 16:07:24 2009
@@ -124,24 +124,6 @@
   }
 
   @Override
-  public final LispObject car()
-  {
-    return car;
-  }
-
-  @Override
-  public final LispObject cdr()
-  {
-    return cdr;
-  }
-
-  @Override
-  public final void setCar(LispObject obj)
-  {
-    car = obj;
-  }
-
-  @Override
   public LispObject RPLACA(LispObject obj)
   {
     car = obj;
@@ -149,12 +131,6 @@
   }
 
   @Override
-  public final void setCdr(LispObject obj)
-  {
-    cdr = obj;
-  }
-
-  @Override
   public LispObject RPLACD(LispObject obj)
   {
     cdr = obj;

Modified: trunk/abcl/src/org/armedbear/lisp/LispObject.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispObject.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispObject.java	Sun Nov 15 16:07:24 2009
@@ -124,13 +124,22 @@
   }
 
 
-  public LispObject car()
+  public final LispObject car()
   {
+    if (this instanceof Cons) {
+      return ((Cons)this).car;
+    } else if (this == NIL) {
+      return NIL;
+    }
     return type_error(this, Symbol.LIST);
   }
 
-  public void setCar(LispObject obj)
+  public final void setCar(LispObject obj)
   {
+      if (this instanceof Cons) {
+          ((Cons)this).car = obj;
+          return;
+      }
     type_error(this, Symbol.CONS);
   }
 
@@ -139,13 +148,23 @@
     return type_error(this, Symbol.CONS);
   }
 
-  public LispObject cdr()
+  public final LispObject cdr()
   {
+    if (this instanceof Cons) {
+      return ((Cons)this).cdr;
+    } else if (this instanceof Nil) {
+      return NIL;
+    }
     return type_error(this, Symbol.LIST);
   }
 
-  public void setCdr(LispObject obj)
+  public final void setCdr(LispObject obj)
   {
+      if (this instanceof Cons) {
+          ((Cons)this).cdr = obj;
+          return;
+      }
+
     type_error(this, Symbol.CONS);
   }
 
@@ -182,7 +201,7 @@
     return type_error(this, Symbol.LIST);
   }
 
-  public LispObject EQ(LispObject obj)
+  final public LispObject EQ(LispObject obj)
   {
     return this == obj ? T : NIL;
   }

Modified: trunk/abcl/src/org/armedbear/lisp/Nil.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Nil.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Nil.java	Sun Nov 15 16:07:24 2009
@@ -105,18 +105,6 @@
     }
 
     @Override
-    public LispObject car()
-    {
-        return this;
-    }
-
-    @Override
-    public LispObject cdr()
-    {
-        return this;
-    }
-
-    @Override
     public final LispObject cadr()
     {
         return this;




More information about the armedbear-cvs mailing list