Ignore:
Timestamp:
Apr 23, 2007, 2:45:35 AM (18 years ago)
Author:
mjs
Message:

Reviewed by Darin.

  • shrink RegexpObjectImp by 4 bytes


Somewhat inexplicably, this seems to be a .33% speedup on JS iBench.


  • kjs/regexp_object.cpp: (KJS::RegExpObjectImpPrivate::RegExpObjectImpPrivate): (RegExpObjectImp::RegExpObjectImp): (RegExpObjectImp::performMatch): (RegExpObjectImp::arrayOfMatches): (RegExpObjectImp::getBackref): (RegExpObjectImp::getLastMatch): (RegExpObjectImp::getLastParen): (RegExpObjectImp::getLeftContext): (RegExpObjectImp::getRightContext): (RegExpObjectImp::getValueProperty): (RegExpObjectImp::putValueProperty):
  • kjs/regexp_object.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r20310 r21031  
    181181*/
    182182
     183struct KJS::RegExpObjectImpPrivate {
     184  // Global search cache / settings
     185  RegExpObjectImpPrivate() : lastInput(""), lastNumSubPatterns(0), multiline(false) { }
     186  UString lastInput;
     187  OwnArrayPtr<int> lastOvector;
     188  unsigned lastNumSubPatterns : 31;
     189  bool multiline              : 1;
     190};
     191
    183192RegExpObjectImp::RegExpObjectImp(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto)
    184 
    185   : InternalFunctionImp(funcProto), lastInput(""), lastNumSubPatterns(0), multiline(false)
     193  : InternalFunctionImp(funcProto)
     194  , d(new RegExpObjectImpPrivate)
    186195{
    187196  // ECMA 15.10.5.1 RegExp.prototype
     
    211220    ASSERT(tmpOvector);
    212221   
    213     lastInput = s;
    214     lastOvector.set(tmpOvector);
    215     lastNumSubPatterns = r->subPatterns();
     222    d->lastInput = s;
     223    d->lastOvector.set(tmpOvector);
     224    d->lastNumSubPatterns = r->subPatterns();
    216225  }
    217226 
     
    224233  // The returned array contains 'result' as first item, followed by the list of matches
    225234  list.append(jsString(result));
    226   if ( lastOvector )
    227     for ( unsigned i = 1 ; i < lastNumSubPatterns + 1 ; ++i )
     235  if (d->lastOvector)
     236    for (unsigned i = 1 ; i < d->lastNumSubPatterns + 1 ; ++i)
    228237    {
    229       int start = lastOvector[2*i];
     238      int start = d->lastOvector[2*i];
    230239      if (start == -1)
    231240        list.append(jsUndefined());
    232241      else {
    233         UString substring = lastInput.substr( start, lastOvector[2*i+1] - start );
     242        UString substring = d->lastInput.substr(start, d->lastOvector[2*i+1] - start);
    234243        list.append(jsString(substring));
    235244      }
    236245    }
    237246  JSObject *arr = exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
    238   arr->put(exec, "index", jsNumber(lastOvector[0]));
    239   arr->put(exec, "input", jsString(lastInput));
     247  arr->put(exec, "index", jsNumber(d->lastOvector[0]));
     248  arr->put(exec, "input", jsString(d->lastInput));
    240249  return arr;
    241250}
     
    243252JSValue *RegExpObjectImp::getBackref(unsigned i) const
    244253{
    245   if (lastOvector && i < lastNumSubPatterns + 1) {
    246     UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i] );
     254  if (d->lastOvector && i < d->lastNumSubPatterns + 1) {
     255    UString substring = d->lastInput.substr(d->lastOvector[2*i], d->lastOvector[2*i+1] - d->lastOvector[2*i] );
    247256    return jsString(substring);
    248257  }
     
    253262JSValue *RegExpObjectImp::getLastMatch() const
    254263{
    255   if (lastOvector) {
    256     UString substring = lastInput.substr(lastOvector[0], lastOvector[1] - lastOvector[0]);
     264  if (d->lastOvector) {
     265    UString substring = d->lastInput.substr(d->lastOvector[0], d->lastOvector[1] - d->lastOvector[0]);
    257266    return jsString(substring);
    258267  }
     
    263272JSValue *RegExpObjectImp::getLastParen() const
    264273{
    265   int i = lastNumSubPatterns;
     274  int i = d->lastNumSubPatterns;
    266275  if (i > 0) {
    267     ASSERT(lastOvector);
    268     UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i]);
     276    ASSERT(d->lastOvector);
     277    UString substring = d->lastInput.substr(d->lastOvector[2*i], d->lastOvector[2*i+1] - d->lastOvector[2*i]);
    269278    return jsString(substring);
    270279  }
     
    275284JSValue *RegExpObjectImp::getLeftContext() const
    276285{
    277   if (lastOvector) {
    278     UString substring = lastInput.substr(0, lastOvector[0]);
     286  if (d->lastOvector) {
     287    UString substring = d->lastInput.substr(0, d->lastOvector[0]);
    279288    return jsString(substring);
    280289  }
     
    285294JSValue *RegExpObjectImp::getRightContext() const
    286295{
    287   if (lastOvector) {
    288     UString s = lastInput;
    289     UString substring = s.substr(lastOvector[1], s.size() - lastOvector[1]);
     296  if (d->lastOvector) {
     297    UString s = d->lastInput;
     298    UString substring = s.substr(d->lastOvector[1], s.size() - d->lastOvector[1]);
    290299    return jsString(substring);
    291300  }
     
    321330      return getBackref(9);
    322331    case Input:
    323       return jsString(lastInput);
     332      return jsString(d->lastInput);
    324333    case Multiline:
    325       return jsBoolean(multiline);
     334      return jsBoolean(d->multiline);
    326335    case LastMatch:
    327336      return getLastMatch();
     
    348357  switch (token) {
    349358    case Input:
    350       lastInput = value->toString(exec);
     359      d->lastInput = value->toString(exec);
    351360      break;
    352361    case Multiline:
    353       multiline = value->toBoolean(exec);
     362      d->multiline = value->toBoolean(exec);
    354363      break;
    355364    default:
Note: See TracChangeset for help on using the changeset viewer.