Bug 883226, part 4 - Remove foldPropertyByValue from the ParseHandler protocol. Instead, just treat it as an optimization in FullParseHandler. r=Waldo.

This commit is contained in:
Jason Orendorff 2013-06-19 14:43:39 -05:00
Родитель d13d530e97
Коммит 60f6a46cbb
3 изменённых файлов: 54 добавлений и 54 удалений

Просмотреть файл

@ -198,8 +198,59 @@ class FullParseHandler
ParseNode *newPropertyAccess(ParseNode *pn, PropertyName *name, uint32_t end) {
return new_<PropertyAccess>(pn, name, pn->pn_pos.begin, end);
}
ParseNode *newPropertyByValue(ParseNode *pn, ParseNode *kid, uint32_t end) {
return new_<PropertyByValue>(pn, kid, pn->pn_pos.begin, end);
private:
/*
* Examine the RHS of a MemberExpression obj[pn], to optimize expressions
* like obj["name"] or obj["0"].
*
* If pn is a number or string constant that's not an index, store the
* corresponding PropertyName in *namep. Otherwise store NULL in *namep.
*
* Also, if pn is a string constant whose value is the ToString of an
* index, morph it to a number.
*
* Return false on OOM.
*/
bool foldConstantIndex(ParseNode *pn, PropertyName **namep) {
if (pn->isKind(PNK_STRING)) {
JSAtom *atom = pn->pn_atom;
uint32_t index;
if (atom->isIndex(&index)) {
pn->setKind(PNK_NUMBER);
pn->setOp(JSOP_DOUBLE);
pn->pn_dval = index;
} else {
*namep = atom->asPropertyName();
return true;
}
} else if (pn->isKind(PNK_NUMBER)) {
double number = pn->pn_dval;
if (number != ToUint32(number)) {
JSContext *cx = tokenStream.getContext();
JSAtom *atom = ToAtom<NoGC>(cx, DoubleValue(number));
if (!atom)
return false;
*namep = atom->asPropertyName();
return true;
}
}
*namep = NULL;
return true;
}
public:
ParseNode *newPropertyByValue(ParseNode *lhs, ParseNode *index, uint32_t end) {
if (foldConstants) {
PropertyName *name;
if (!foldConstantIndex(index, &name))
return null();
if (name)
return newPropertyAccess(lhs, name, end);
}
return new_<PropertyByValue>(lhs, index, lhs->pn_pos.begin, end);
}
inline bool addCatchBlock(ParseNode *catchList, ParseNode *letBlock,

Просмотреть файл

@ -6288,50 +6288,6 @@ Parser<ParseHandler>::argumentList(Node listNode)
return true;
}
template <>
PropertyName *
Parser<FullParseHandler>::foldPropertyByValue(ParseNode *pn)
{
/*
* Optimize property name lookups. If the name is a PropertyName,
* then make a name-based node so the emitter will use a name-based
* bytecode. Otherwise make a node using the property expression
* by value. If the node is a string containing an index, convert
* it to a number to save work later.
*/
uint32_t index;
if (foldConstants) {
if (pn->isKind(PNK_STRING)) {
JSAtom *atom = pn->pn_atom;
if (atom->isIndex(&index)) {
pn->setKind(PNK_NUMBER);
pn->setOp(JSOP_DOUBLE);
pn->pn_dval = index;
} else {
return atom->asPropertyName();
}
} else if (pn->isKind(PNK_NUMBER)) {
double number = pn->pn_dval;
if (number != ToUint32(number)) {
JSAtom *atom = ToAtom<NoGC>(context, DoubleValue(number));
if (!atom)
return NULL;
return atom->asPropertyName();
}
}
}
return NULL;
}
template <>
PropertyName *
Parser<SyntaxParseHandler>::foldPropertyByValue(Node pn)
{
return NULL;
}
template <typename ParseHandler>
typename ParseHandler::Node
Parser<ParseHandler>::memberExpr(TokenKind tt, bool allowCallSyntax)
@ -6392,13 +6348,7 @@ Parser<ParseHandler>::memberExpr(TokenKind tt, bool allowCallSyntax)
if (foldConstants && !FoldConstants(context, &propExpr, this))
return null();
PropertyName *name = foldPropertyByValue(propExpr);
uint32_t end = pos().end;
if (name)
nextMember = handler.newPropertyAccess(lhs, name, end);
else
nextMember = handler.newPropertyByValue(lhs, propExpr, end);
nextMember = handler.newPropertyByValue(lhs, propExpr, pos().end);
if (!nextMember)
return null();
} else if (allowCallSyntax && tt == TOK_LP) {

Просмотреть файл

@ -506,7 +506,6 @@ struct Parser : private AutoGCRooter, public StrictModeGetter
bool bindDestructuringVar(BindData<ParseHandler> *data, Node pn);
bool bindDestructuringLHS(Node pn);
bool makeSetCall(Node pn, unsigned msg);
PropertyName *foldPropertyByValue(Node pn);
Node cloneLeftHandSide(Node opn);
Node cloneParseTree(Node opn);