Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit b28899c

Browse files
committed
optimize ZString
1 parent 0a69aec commit b28899c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

daedalus/ZString.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ static std::shared_ptr<std::string> emptyStr() {
99
return v;
1010
}
1111

12+
static std::shared_ptr<std::string> strFrmChr(std::string&& s) {
13+
if(s.empty())
14+
return emptyStr();
15+
return std::make_shared<std::string>(std::move(s));
16+
}
17+
1218
static ZString strFromIntCache(uint8_t v){
1319
static ZString intCache[256];
1420
if(intCache[v].empty()){
@@ -30,11 +36,11 @@ ZString::ZString(const char* s) {
3036
}
3137

3238
ZString::ZString(std::string&& s)
33-
:val(std::make_shared<std::string>(std::move(s))){
39+
:val(strFrmChr(std::move(s))){
3440
}
3541

3642
ZString::ZString(std::unique_ptr<char[]>&& s)
37-
:val(std::make_shared<std::string>(s.get())){
43+
:val(strFrmChr(s.get())){
3844
}
3945

4046
ZString::ZString(ZenLoad::ZenParser &input) {

0 commit comments

Comments
 (0)