Bug 808245, Part 2/6 - Remove the unused hackedSource RegExp type. r=dvander
authorSean Stangl <sstangl@mozilla.com>
Wed, 12 Dec 2012 16:37:15 -0800
changeset 125217 787527f064da7720dab2b28002e887462ee56bd6
parent 125216 9121bae603a2fba721938e27bc1c4981cc59d24c
child 125218 ea7d93401f966c3cb68fe07d8b989514747f3a1a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs808245
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808245, Part 2/6 - Remove the unused hackedSource RegExp type. r=dvander
js/src/builtin/RegExp.cpp
js/src/vm/RegExpObject.cpp
js/src/vm/RegExpObject.h
--- a/js/src/builtin/RegExp.cpp
+++ b/js/src/builtin/RegExp.cpp
@@ -525,64 +525,26 @@ js_InitRegExpClass(JSContext *cx, Handle
     AddTypeProperty(cx, type, "lastIndex", Type::Int32Type());
 
     if (!DefineConstructorAndPrototype(cx, global, JSProto_RegExp, ctor, proto))
         return NULL;
 
     return proto;
 }
 
-
-static const jschar GreedyStarChars[] = {'.', '*'};
-
-static inline bool
-StartsWithGreedyStar(JSAtom *source)
-{
-    return false;
-
-#if 0
-    if (source->length() < 3)
-        return false;
-
-    const jschar *chars = source->chars();
-    return chars[0] == GreedyStarChars[0] &&
-           chars[1] == GreedyStarChars[1] &&
-           chars[2] != '?';
-#endif
-}
-
-static inline bool
-GetSharedForGreedyStar(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGuard *g)
-{
-    if (cx->compartment->regExps.lookupHack(source, flags, cx, g))
-        return true;
-
-    JSAtom *hackedSource = AtomizeChars(cx, source->chars() + ArrayLength(GreedyStarChars),
-                                        source->length() - ArrayLength(GreedyStarChars));
-    if (!hackedSource)
-        return false;
-
-    return cx->compartment->regExps.getHack(cx, source, hackedSource, flags, g);
-}
-
 bool
 js::ExecuteRegExp(JSContext *cx, RegExpExecType execType, HandleObject regexp,
                   HandleString string, MutableHandleValue rval)
 {
     /* Step 1 (b) was performed by CallNonGenericMethod. */
     Rooted<RegExpObject*> reobj(cx, &regexp->asRegExp());
 
     RegExpGuard re;
-    if (StartsWithGreedyStar(reobj->getSource())) {
-        if (!GetSharedForGreedyStar(cx, reobj->getSource(), reobj->getFlags(), &re))
-            return false;
-    } else {
-        if (!reobj->getShared(cx, &re))
-            return false;
-    }
+    if (!reobj->getShared(cx, &re))
+        return false;
 
     RegExpStatics *res = cx->regExpStatics();
 
     /* Step 3. */
     Rooted<JSStableString*> stableInput(cx, string->ensureStable(cx));
     if (!stableInput)
         return false;
 
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -555,20 +555,19 @@ RegExpCompartment::sweep(JSRuntime *rt)
         if (shared->activeUseCount == 0 && shared->gcNumberWhenUsed < rt->gcStartNumber) {
             js_delete(shared);
             e.removeFront();
         }
     }
 }
 
 inline bool
-RegExpCompartment::get(JSContext *cx, JSAtom *keyAtom, JSAtom *source, RegExpFlag flags, Type type,
-                       RegExpGuard *g)
+RegExpCompartment::get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGuard *g)
 {
-    Key key(keyAtom, flags, type);
+    Key key(source, flags);
     Map::AddPtr p = map_.lookupForAdd(key);
     if (p) {
         g->init(*p->value);
         return true;
     }
 
     ScopedDeletePtr<RegExpShared> shared(cx->new_<RegExpShared>(cx->runtime, flags));
     if (!shared)
@@ -594,39 +593,16 @@ RegExpCompartment::get(JSContext *cx, JS
      * safe since 'shared' cannot be deleted by GC until after the call to
      * map_.relookupOrAdd() directly above.
      */
     g->init(*shared.forget());
     return true;
 }
 
 bool
-RegExpCompartment::get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGuard *g)
-{
-    return get(cx, source, source, flags, Normal, g);
-}
-
-bool
-RegExpCompartment::getHack(JSContext *cx, JSAtom *source, JSAtom *hackedSource, RegExpFlag flags,
-                           RegExpGuard *g)
-{
-    return get(cx, source, hackedSource, flags, Hack, g);
-}
-
-bool
-RegExpCompartment::lookupHack(JSAtom *source, RegExpFlag flags, JSContext *cx, RegExpGuard *g)
-{
-    if (Map::Ptr p = map_.lookup(Key(source, flags, Hack))) {
-        g->init(*p->value);
-        return true;
-    }
-    return false;
-}
-
-bool
 RegExpCompartment::get(JSContext *cx, JSAtom *atom, JSString *opt, RegExpGuard *g)
 {
     RegExpFlag flags = RegExpFlag(0);
     if (opt && !ParseRegExpFlags(cx, opt, &flags))
         return false;
 
     return get(cx, atom, flags, g);
 }
--- a/js/src/vm/RegExpObject.h
+++ b/js/src/vm/RegExpObject.h
@@ -235,31 +235,28 @@ class RegExpGuard
     bool initialized() const { return !!re_; }
     RegExpShared *re() const { JS_ASSERT(initialized()); return re_; }
     RegExpShared *operator->() { return re(); }
     RegExpShared &operator*() { return *re(); }
 };
 
 class RegExpCompartment
 {
-    enum Type { Normal = 0x0, Hack = 0x1 };
-
     struct Key {
         JSAtom *atom;
         uint16_t flag;
-        uint16_t type;
         Key() {}
-        Key(JSAtom *atom, RegExpFlag flag, Type type)
-          : atom(atom), flag(flag), type(type) {}
+        Key(JSAtom *atom, RegExpFlag flag)
+          : atom(atom), flag(flag) {}
         typedef Key Lookup;
         static HashNumber hash(const Lookup &l) {
-            return DefaultHasher<JSAtom *>::hash(l.atom) ^ (l.flag << 1) ^ l.type;
+            return DefaultHasher<JSAtom *>::hash(l.atom) ^ (l.flag << 1);
         }
         static bool match(Key l, Key r) {
-            return l.atom == r.atom && l.flag == r.flag && l.type == r.type;
+            return l.atom == r.atom && l.flag == r.flag;
         }
     };
 
     /*
      * Cache to reuse RegExpShareds with the same source/flags/etc. The cache
      * is entirely cleared on each GC.
      */
     typedef HashMap<Key, RegExpShared *, Key, RuntimeAllocPolicy> Map;
@@ -268,53 +265,29 @@ class RegExpCompartment
     /*
      * The set of all RegExpShareds in the compartment. On every GC, every
      * RegExpShared that is not actively being used is deleted and removed from
      * the set.
      */
     typedef HashSet<RegExpShared *, DefaultHasher<RegExpShared*>, RuntimeAllocPolicy> PendingSet;
     PendingSet inUse_;
 
-    bool get(JSContext *cx, JSAtom *key, JSAtom *source, RegExpFlag flags, Type type,
-             RegExpGuard *g);
-
   public:
     RegExpCompartment(JSRuntime *rt);
     ~RegExpCompartment();
 
     bool init(JSContext *cx);
     void sweep(JSRuntime *rt);
 
     /* Return a regexp corresponding to the given (source, flags) pair. */
     bool get(JSContext *cx, JSAtom *source, RegExpFlag flags, RegExpGuard *g);
 
     /* Like 'get', but compile 'maybeOpt' (if non-null). */
     bool get(JSContext *cx, JSAtom *source, JSString *maybeOpt, RegExpGuard *g);
 
-    /*
-     * A 'hacked' RegExpShared is one where the input 'source' doesn't match
-     * what is actually compiled in the regexp. To compile a hacked regexp,
-     * getHack may be called providing both the original 'source' and the
-     * 'hackedSource' which should actually be compiled. For a given 'source'
-     * there may only ever be one corresponding 'hackedSource'. Thus, we assume
-     * there is some single pure function mapping 'source' to 'hackedSource'
-     * that is always respected in calls to getHack. Note that this restriction
-     * only applies to 'getHack': a single 'source' value may be passed to both
-     * 'get' and 'getHack'.
-     */
-    bool getHack(JSContext *cx, JSAtom *source, JSAtom *hackedSource, RegExpFlag flags,
-                 RegExpGuard *g);
-
-    /*
-     * To avoid atomizing 'hackedSource', callers may call 'lookupHack',
-     * passing only the original 'source'. Due to the abovementioned unique
-     * mapping property, 'hackedSource' is unambiguous.
-     */
-    bool lookupHack(JSAtom *source, RegExpFlag flags, JSContext *cx, RegExpGuard *g);
-
     size_t sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf);
 };
 
 class RegExpObject : public JSObject
 {
     typedef detail::RegExpCode RegExpCode;
 
     static const unsigned LAST_INDEX_SLOT          = 0;