From 5a3b4016473c3806fa364edb446cdd5613d9010f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 24 Jan 2011 20:58:58 -0500 Subject: [PATCH] Began moving abstract logic out of propCopy --- lib/class.js | 19 +++++++++++++++++-- lib/util.js | 7 ------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/class.js b/lib/class.js index f448478..a4cce68 100644 --- a/lib/class.js +++ b/lib/class.js @@ -217,6 +217,15 @@ var extend = ( function( extending ) members = member_builder.initMembers( prototype ), abstract_methods = ( base.abstractMethods || [] ).slice(); + // it's much faster to lookup a hash than it is to iterate through an + // entire array each time we need to find an existing abstract method + var abstract_map = {}; + for ( var i = 0, len = abstract_methods.length; i < len; i++ ) + { + var method = abstract_methods[ i ]; + abstract_map[ method ] = i; + } + util.propCopy( props, prototype, { each: function( name, value ) { @@ -239,12 +248,18 @@ var extend = ( function( extending ) { var pre = prototype[ name ]; + this.performDefault( name, func, is_abstract ); + if ( ( pre === undefined ) && is_abstract ) { abstract_methods.push( name ); } - - this.performDefault( name, func, is_abstract ); + else if ( pre && ( is_abstract === false ) ) + { + // if this was a concrete method, then it should no longer + // be marked as abstract + delete abstract_methods[ abstract_map[ name ] ]; + } }, methodOverride: function( name, pre, func ) diff --git a/lib/util.js b/lib/util.js index f4aa8d3..ebb1ff7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -449,13 +449,6 @@ exports.overrideMethod = function( ); } } - - // if this was a concrete method, then it should no longer be marked as - // abstract - if ( is_abstract === false ) - { - delete abstract_methods[ abstract_map[ name ] ]; - } } // this is the method that will be invoked when the requested