Macro processor: ensure that all read-accessors return a const reference

Useless copies are thus avoided in some situations.
issue#70
Sébastien Villemot 2019-08-14 17:36:10 +02:00
parent 8c1e48a09e
commit 75b000a0b5
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 9 additions and 9 deletions

View File

@ -71,7 +71,7 @@ namespace macro
Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro) override;
inline string getName() const { return name; }
inline const string & getName() const { return name; }
};
@ -84,7 +84,7 @@ namespace macro
IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) :
Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { }
void interpret(ostream &output, bool no_line_macro) override;
inline string getPath() const { return path; }
inline const string & getPath() const { return path; }
};

View File

@ -378,8 +378,8 @@ namespace macro
public:
inline size_t size() const { return tup.size(); }
inline bool empty() const { return tup.empty(); }
inline vector<ExpressionPtr> getValue() const { return tup; }
inline ExpressionPtr at(int i) const { return tup.at(i); }
inline const vector<ExpressionPtr> & getValue() const { return tup; }
inline const ExpressionPtr & at(int i) const { return tup.at(i); }
BoolPtr is_equal(const BaseTypePtr &btp) const override;
inline BoolPtr istuple() const override { return make_shared<Bool>(true, env, location); }
BoolPtr contains(const BaseTypePtr &btp) const override;
@ -418,8 +418,8 @@ namespace macro
ExpressionPtr clone() const noexcept override;
public:
inline size_t size() const { return arr.size(); }
inline vector<ExpressionPtr> getValue() const { return arr; }
inline ExpressionPtr at(int i) const { return arr.at(i); }
inline const vector<ExpressionPtr> & getValue() const { return arr; }
inline const ExpressionPtr & at(int i) const { return arr.at(i); }
inline bool empty() const { return arr.empty() && !range1 && !range2; }
BaseTypePtr plus(const BaseTypePtr &bt) const override;
BaseTypePtr minus(const BaseTypePtr &bt) const override;
@ -466,7 +466,7 @@ namespace macro
make_shared<Variable>(name, env, location);
}
public:
inline string getName() const noexcept { return name; }
inline const string & getName() const noexcept { return name; }
inline codes::BaseType getType() const { return env.getType(name); }
};
@ -491,8 +491,8 @@ namespace macro
public:
inline void printName(ostream &output) const noexcept { output << name; }
void printArgs(ostream &output) const noexcept;
inline string getName() const { return name; }
inline vector<ExpressionPtr> getArgs() const { return args; }
inline const string & getName() const { return name; }
inline const vector<ExpressionPtr> & getArgs() const { return args; }
};