const & added

This commit is contained in:
VaclavT 2021-02-11 23:39:53 +01:00
parent 3d119f8c87
commit 96fc47099c
2 changed files with 3 additions and 3 deletions

4
ml.cpp
View File

@ -104,7 +104,7 @@ std::string read_file_contents(const std::string &filename) {
#define to_string(x) static_cast<std::ostringstream>((std::ostringstream() << std::dec << x )).str() #define to_string(x) static_cast<std::ostringstream>((std::ostringstream() << std::dec << x )).str()
// Replace a substring with a replacement string in a source string // Replace a substring with a replacement string in a source string
void replace_substring(std::string &src, std::string substr, std::string replacement) { void replace_substring(std::string &src, const std::string& substr, const std::string &replacement) {
size_t i = 0; size_t i = 0;
for (i = src.find(substr, i); i != std::string::npos; i = src.find(substr, i)) { for (i = src.find(substr, i); i != std::string::npos; i = src.find(substr, i)) {
src.replace(i, substr.size(), replacement); src.replace(i, substr.size(), replacement);
@ -148,7 +148,7 @@ MlValue::MlValue(double f) : type(FLOAT) { stack_data.f = f; }
MlValue::MlValue(const std::vector<MlValue> &list) : type(LIST), list(list) {} MlValue::MlValue(const std::vector<MlValue> &list) : type(LIST), list(list) {}
MlValue MlValue::quote(MlValue quoted) { MlValue MlValue::quote(const MlValue &quoted) {
MlValue result; MlValue result;
result.type = QUOTE; result.type = QUOTE;

2
ml.h
View File

@ -89,7 +89,7 @@ typedef MlValue (*Builtin)(std::vector<MlValue>, MlEnvironment &);
MlValue(const std::vector<MlValue> &list); MlValue(const std::vector<MlValue> &list);
// Construct a quoted value // Construct a quoted value
static MlValue quote(MlValue quoted); static MlValue quote(const MlValue& quoted);
// Construct an atom // Construct an atom
static MlValue atom(const std::string &s); static MlValue atom(const std::string &s);