Improve performance of cloning StringEvalValue
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1f3ab9243e
commit
3b344d6d72
|
@ -10,12 +10,16 @@ using namespace std;
|
|||
|
||||
namespace Porygon::Evaluation {
|
||||
class StringEvalValue : public EvalValue {
|
||||
u16string _value;
|
||||
shared_ptr<u16string> _value;
|
||||
size_t _hash;
|
||||
public:
|
||||
explicit StringEvalValue(u16string s) : _value(move(s)){
|
||||
_hash = Utilities::HashedString::ConstHash(_value.c_str());
|
||||
explicit StringEvalValue(shared_ptr<u16string> s) : _value(move(s)){
|
||||
_hash = Utilities::HashedString::ConstHash(_value->c_str());
|
||||
}
|
||||
public:
|
||||
explicit StringEvalValue(const u16string& s) : _value(make_shared<u16string>(s)){
|
||||
_hash = Utilities::HashedString::ConstHash(_value->c_str());
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
inline TypeClass GetTypeClass() const final {
|
||||
|
@ -30,7 +34,7 @@ namespace Porygon::Evaluation {
|
|||
|
||||
[[nodiscard]]
|
||||
inline u16string EvaluateString() const final {
|
||||
return _value;
|
||||
return *_value.get();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
|
@ -41,7 +45,7 @@ namespace Porygon::Evaluation {
|
|||
EvalValue* IndexValue(const EvalValue *val) const final {
|
||||
// Porygon is 1-indexed, so we convert to that.
|
||||
auto l = val->EvaluateInteger() - 1;
|
||||
return new StringEvalValue(u16string(1, _value[l]));
|
||||
return new StringEvalValue(u16string(1, (*_value)[l]));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
|
@ -55,9 +59,10 @@ namespace Porygon::Evaluation {
|
|||
throw EvaluationException("Binary operation not supported for strings.");
|
||||
}
|
||||
std::basic_ostringstream<char16_t> stringStream;
|
||||
stringStream << _value;
|
||||
stringStream << *_value;
|
||||
stringStream << b->EvaluateString();
|
||||
return new StringEvalValue(stringStream.str());
|
||||
auto str = stringStream.str();
|
||||
return new StringEvalValue(str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue