Changeset 13811


Ignore:
Timestamp:
01/26/12 23:48:18 (9 years ago)
Author:
ehuelsmann
Message:

Performance improvement: Don't allocate a new environment and
don't snapshot the special bindings on each call to a function with
keyword arguments [which includes compiled functions!].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Closure.java

    r13461 r13811  
    657657  }
    658658
    659   protected final LispObject[] processArgs(LispObject[] args, LispThread thread)
    660 
    661   {
    662     if (optionalParameters.length == 0 && keywordParameters.length == 0)
    663       return fastProcessArgs(args);
    664     final int argsLength = args.length;
    665     if (arity >= 0)
    666       {
    667         // Fixed arity.
    668         if (argsLength != arity)
    669           error(new WrongNumberOfArgumentsException(this, arity));
    670         return args;
    671       }
    672     // Not fixed arity.
    673     if (argsLength < minArgs)
    674       error(new WrongNumberOfArgumentsException(this, minArgs, -1));
    675     final LispObject[] array = new LispObject[variables.length];
    676     int index = 0;
    677     // The bindings established here (if any) are lost when this function
    678     // returns. They are used only in the evaluation of initforms for
    679     // optional and keyword arguments.
    680     final SpecialBindingsMark mark = thread.markSpecialBindings();
    681     Environment ext = new Environment(environment);
    682     // Section 3.4.4: "...the &environment parameter is bound along with
    683     // &whole before any other variables in the lambda list..."
    684     try {
     659 
     660  private LispObject[] _processArgs(LispObject[] args, LispThread thread,
     661          Environment ext) {
     662        final LispObject[] array = new LispObject[variables.length];
     663        int index = 0;
     664
     665        int argsLength = args.length;
     666       
    685667        if (bindInitForms)
    686668          if (envVar != null)
     
    910892              }
    911893          }
     894        return array;
     895  }
     896 
     897  protected final LispObject[] processArgs(LispObject[] args, LispThread thread)
     898
     899  {
     900    if (optionalParameters.length == 0 && keywordParameters.length == 0)
     901      return fastProcessArgs(args);
     902    if (arity >= 0)
     903      {
     904        // Fixed arity.
     905        if (args.length != arity)
     906          error(new WrongNumberOfArgumentsException(this, arity));
     907        return args;
     908      }
     909    // Not fixed arity.
     910    if (args.length < minArgs)
     911      error(new WrongNumberOfArgumentsException(this, minArgs, -1));
     912   
     913    if (!bindInitForms)
     914        return _processArgs(args, thread, environment);
     915   
     916    // The bindings established here (if any) are lost when this function
     917    // returns. They are used only in the evaluation of initforms for
     918    // optional and keyword arguments.
     919    final SpecialBindingsMark mark = thread.markSpecialBindings();
     920    Environment ext = new Environment(environment);
     921    // Section 3.4.4: "...the &environment parameter is bound along with
     922    // &whole before any other variables in the lambda list..."
     923    try {
     924        return _processArgs(args, thread, ext);
    912925    }
    913926    finally {
    914927        thread.resetSpecialBindings(mark);
    915928    }
    916     return array;
    917929  }
    918930
Note: See TracChangeset for help on using the changeset viewer.