Bug 808245, Part 2/6 - Remove the unused hackedSource RegExp type. r=dvander

This commit is contained in:
Sean Stangl 2012-12-12 16:37:15 -08:00
parent b100af61f1
commit 60f9730397
3 changed files with 8 additions and 97 deletions

View File

@ -530,39 +530,6 @@ js_InitRegExpClass(JSContext *cx, HandleObject obj)
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)
@ -571,13 +538,8 @@ js::ExecuteRegExp(JSContext *cx, RegExpExecType execType, HandleObject regexp,
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();

View File

@ -560,10 +560,9 @@ RegExpCompartment::sweep(JSRuntime *rt)
}
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);
@ -598,29 +597,6 @@ RegExpCompartment::get(JSContext *cx, JSAtom *keyAtom, JSAtom *source, RegExpFla
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)
{

View File

@ -240,21 +240,18 @@ class RegExpGuard
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;
}
};
@ -273,9 +270,6 @@ class RegExpCompartment
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();
@ -289,27 +283,6 @@ class RegExpCompartment
/* 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);
};