Don't pass Symbol by reference

Since Symbol is just an integer, passing it by const reference is
never advantageous.
This commit is contained in:
Eelco Dolstra 2022-04-26 13:23:32 +02:00
parent 29e52194a8
commit fab731a9d4
4 changed files with 13 additions and 12 deletions

View file

@ -26,7 +26,7 @@ Bindings * EvalState::allocBindings(size_t capacity)
/* Create a new attribute named 'name' on an existing attribute set stored /* Create a new attribute named 'name' on an existing attribute set stored
in 'vAttrs' and return the newly allocated Value which is associated with in 'vAttrs' and return the newly allocated Value which is associated with
this attribute. */ this attribute. */
Value * EvalState::allocAttr(Value & vAttrs, const Symbol & name) Value * EvalState::allocAttr(Value & vAttrs, Symbol name)
{ {
Value * v = allocValue(); Value * v = allocValue();
vAttrs.attrs->push_back(Attr(name, v)); vAttrs.attrs->push_back(Attr(name, v));
@ -40,7 +40,7 @@ Value * EvalState::allocAttr(Value & vAttrs, std::string_view name)
} }
Value & BindingsBuilder::alloc(const Symbol & name, PosIdx pos) Value & BindingsBuilder::alloc(Symbol name, PosIdx pos)
{ {
auto value = state.allocValue(); auto value = state.allocValue();
bindings->push_back(Attr(name, value, pos)); bindings->push_back(Attr(name, value, pos));

View file

@ -66,7 +66,7 @@ public:
attrs[size_++] = attr; attrs[size_++] = attr;
} }
iterator find(const Symbol & name) iterator find(Symbol name)
{ {
Attr key(name, 0); Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key); iterator i = std::lower_bound(begin(), end(), key);
@ -74,7 +74,7 @@ public:
return end(); return end();
} }
Attr * get(const Symbol & name) Attr * get(Symbol name)
{ {
Attr key(name, 0); Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key); iterator i = std::lower_bound(begin(), end(), key);
@ -143,7 +143,7 @@ public:
bindings->push_back(attr); bindings->push_back(attr);
} }
Value & alloc(const Symbol & name, PosIdx pos = noPos); Value & alloc(Symbol name, PosIdx pos = noPos);
Value & alloc(std::string_view name, PosIdx pos = noPos); Value & alloc(std::string_view name, PosIdx pos = noPos);

View file

@ -392,7 +392,7 @@ public:
inline Value * allocValue(); inline Value * allocValue();
inline Env & allocEnv(size_t size); inline Env & allocEnv(size_t size);
Value * allocAttr(Value & vAttrs, const Symbol & name); Value * allocAttr(Value & vAttrs, Symbol name);
Value * allocAttr(Value & vAttrs, std::string_view name); Value * allocAttr(Value & vAttrs, std::string_view name);
Bindings * allocBindings(size_t capacity); Bindings * allocBindings(size_t capacity);

View file

@ -128,7 +128,7 @@ struct AttrName
{ {
Symbol symbol; Symbol symbol;
Expr * expr; Expr * expr;
AttrName(const Symbol & s) : symbol(s) {}; AttrName(Symbol s) : symbol(s) {};
AttrName(Expr * e) : expr(e) {}; AttrName(Expr * e) : expr(e) {};
}; };
@ -211,8 +211,8 @@ struct ExprVar : Expr
Level level; Level level;
Displacement displ; Displacement displ;
ExprVar(const Symbol & name) : name(name) { }; ExprVar(Symbol name) : name(name) { };
ExprVar(const PosIdx & pos, const Symbol & name) : pos(pos), name(name) { }; ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { };
COMMON_METHODS COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env); Value * maybeThunk(EvalState & state, Env & env);
}; };
@ -223,7 +223,7 @@ struct ExprSelect : Expr
Expr * e, * def; Expr * e, * def;
AttrPath attrPath; AttrPath attrPath;
ExprSelect(const PosIdx & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { }; ExprSelect(const PosIdx & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { };
ExprSelect(const PosIdx & pos, Expr * e, const Symbol & name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); }; ExprSelect(const PosIdx & pos, Expr * e, Symbol name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
COMMON_METHODS COMMON_METHODS
}; };
@ -283,7 +283,8 @@ struct Formals
Formals_ formals; Formals_ formals;
bool ellipsis; bool ellipsis;
bool has(Symbol arg) const { bool has(Symbol arg) const
{
auto it = std::lower_bound(formals.begin(), formals.end(), arg, auto it = std::lower_bound(formals.begin(), formals.end(), arg,
[] (const Formal & f, const Symbol & sym) { return f.name < sym; }); [] (const Formal & f, const Symbol & sym) { return f.name < sym; });
return it != formals.end() && it->name == arg; return it != formals.end() && it->name == arg;
@ -450,7 +451,7 @@ struct StaticEnv
vars.erase(it, end); vars.erase(it, end);
} }
Vars::const_iterator find(const Symbol & name) const Vars::const_iterator find(Symbol name) const
{ {
Vars::value_type key(name, 0); Vars::value_type key(name, 0);
auto i = std::lower_bound(vars.begin(), vars.end(), key); auto i = std::lower_bound(vars.begin(), vars.end(), key);