2121#include < vector>
2222
2323#include " string_piece.h"
24+ #include " string_piece_util.h"
2425
2526struct Rule ;
2627
2728// / An interface for a scope for variable (e.g. "$foo") lookups.
2829struct Env {
2930 virtual ~Env () {}
30- virtual std::string LookupVariable (const std::string& var) = 0;
31+ virtual std::string LookupVariable (StringPiece var) = 0;
3132};
3233
3334// / A tokenized string that contains variable references.
@@ -74,16 +75,16 @@ struct Rule {
7475
7576 void AddBinding (const std::string& key, const EvalString& val);
7677
77- static bool IsReservedBinding (const std::string& var);
78+ static bool IsReservedBinding (StringPiece var);
7879
79- const EvalString* GetBinding (const std::string& key) const ;
80+ const EvalString* GetBinding (StringPiece key) const ;
8081
8182 private:
8283 // Allow the parsers to reach into this object and fill out its fields.
8384 friend struct ManifestParser ;
8485
8586 std::string name_;
86- typedef std::map<std::string, EvalString> Bindings;
87+ typedef std::map<std::string, EvalString, StringPieceLess > Bindings;
8788 Bindings bindings_;
8889 bool phony_ = false ;
8990};
@@ -95,26 +96,27 @@ struct BindingEnv : public Env {
9596 explicit BindingEnv (BindingEnv* parent) : parent_(parent) {}
9697
9798 virtual ~BindingEnv () {}
98- virtual std::string LookupVariable (const std::string& var);
99+ virtual std::string LookupVariable (StringPiece var);
99100
100101 void AddRule (std::unique_ptr<const Rule> rule);
101- const Rule* LookupRule (const std::string& rule_name);
102- const Rule* LookupRuleCurrentScope (const std::string& rule_name);
103- const std::map<std::string, std::unique_ptr<const Rule>>& GetRules () const ;
102+ const Rule* LookupRule (StringPiece rule_name);
103+ const Rule* LookupRuleCurrentScope (StringPiece rule_name);
104+ const std::map<std::string, std::unique_ptr<const Rule>, StringPieceLess>&
105+ GetRules () const ;
104106
105- void AddBinding (const std::string& key, const std::string& val);
107+ void AddBinding (const std::string& key, StringPiece val);
106108
107109 // / This is tricky. Edges want lookup scope to go in this order:
108110 // / 1) value set on edge itself (edge_->env_)
109111 // / 2) value set on rule, with expansion in the edge's scope
110112 // / 3) value set on enclosing scope of edge (edge_->env_->parent_)
111113 // / This function takes as parameters the necessary info to do (2).
112- std::string LookupWithFallback (const std::string& var, const EvalString* eval,
114+ std::string LookupWithFallback (StringPiece var, const EvalString* eval,
113115 Env* env);
114116
115117private:
116- std::map<std::string, std::string> bindings_;
117- std::map<std::string, std::unique_ptr<const Rule>> rules_;
118+ std::map<std::string, std::string, StringPieceLess > bindings_;
119+ std::map<std::string, std::unique_ptr<const Rule>, StringPieceLess > rules_;
118120 BindingEnv* parent_;
119121};
120122
0 commit comments