Skip to content

Commit 8ca20ce

Browse files
authored
speed up
1 parent 885975b commit 8ca20ce

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

source/global.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,42 @@ namespace wiz {
370370
return DataType(str) + type;
371371
}
372372

373+
int tokenize_pre(std::string_view sv, char ch) {
374+
int count = 0;
375+
376+
size_t x;
377+
if ((x = sv.find(ch)) == std::string::npos) {
378+
if (!sv.empty()) {
379+
count++;
380+
}
381+
return count;
382+
}
383+
384+
if (x > 0) {
385+
count++;
386+
}
387+
388+
size_t y;
389+
while (x != std::string::npos) {
390+
y = sv.find(ch, x + 1);
391+
392+
if (y == std::string::npos) {
393+
if (x + 1 < sv.size()) {
394+
count++;
395+
}
396+
break;
397+
}
398+
else {
399+
if (y - 1 - x + 1 > 0) {
400+
count++;
401+
}
402+
}
403+
404+
x = y;
405+
}
406+
407+
return count;
408+
}
373409

374410
std::vector<std::string> tokenize(std::string sv, char ch) {
375411
std::vector<std::string> result;

source/load_data.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,10 @@ namespace wiz {
11091109
size_t item_count = 0;
11101110
ArrayStack<WIZ_STRING_TYPE> operandStack;
11111111

1112+
if (temp.GetItemListSize() > 0) {
1113+
operandStack.reserve(temp.GetItemListSize());
1114+
}
1115+
11121116
for (size_t i = 0; i < temp.GetIListSize(); ++i) {
11131117
if (i > 0) {
11141118
result += " ";
@@ -1122,7 +1126,9 @@ namespace wiz {
11221126
else {
11231127
if (!String::startsWith(temp.GetUserTypeList(user_count)->GetName(), "$")) {
11241128
if (!temp.GetUserTypeList(user_count)->GetName().empty()) {
1125-
result += " " + temp.GetUserTypeList(user_count)->GetName() + " = { ";
1129+
result += " ";
1130+
result += temp.GetUserTypeList(user_count)->GetName();
1131+
result += " = { ";
11261132
}
11271133
else {
11281134
result += " { ";
@@ -1150,6 +1156,10 @@ namespace wiz {
11501156
if (String::startsWith(temp.GetName(), "$") && temp.GetName().size() > 1) {
11511157
wiz::ArrayStack<WIZ_STRING_TYPE> _stack;
11521158

1159+
if (!operandStack.empty()) {
1160+
_stack.reserve(operandStack.size());
1161+
}
1162+
11531163
while (operandStack.empty() == false) {
11541164
_stack.push(operandStack.pop());
11551165
}
@@ -1170,15 +1180,26 @@ namespace wiz {
11701180
{
11711181
WIZ_STRING_TYPE result;
11721182
if (temp.GetName().empty() == false) {
1173-
result += temp.GetName() + " = ";
1183+
result += temp.GetName();
1184+
result += " = ";
1185+
}
1186+
1187+
int count = 0;
1188+
auto temp_val = temp.Get();
1189+
1190+
if (auto x = temp_val.find('/'); x != std::string::npos) {
1191+
count++;
11741192
}
11751193

1176-
auto tokens = tokenize(temp.Get(), '/');
1194+
auto tokens_pre = tokenize_pre(temp_val, '/');
11771195

1178-
if (tokens.size() <= 1) {
1179-
return result + ToBool4(now, global, temp.Get(), executeData);
1196+
if (tokens_pre <= 1) {
1197+
return result + ToBool4(now, global, temp_val, executeData);
11801198
}
1181-
1199+
1200+
auto tokens = tokenize(temp_val, '/');
1201+
1202+
11821203
WIZ_STRING_TYPE _result = "/";
11831204

11841205
for (int i = 0; i < tokens.size(); ++i) {
@@ -1197,17 +1218,17 @@ namespace wiz {
11971218

11981219
WIZ_STRING_TYPE LoadData::ToBool4(wiz::load_data::UserType* now, wiz::load_data::UserType& global, const std::string& temp, const ExecuteData& executeData) {
11991220
std::string result;
1200-
if (String::startsWith(temp, "$local.")) {
1221+
if (String::startsWith(temp, "$local."sv)) {
12011222
if (!(result = FindLocals(executeData.info.locals, temp)).empty()) {
12021223
return result;
12031224
}
12041225
}
1205-
else if (String::startsWith(temp, "$parameter.")) {
1226+
else if (String::startsWith(temp, "$parameter."sv)) {
12061227
if (!(result = FindParameters(executeData.info.parameters, temp)).empty()) {
12071228
return result;
12081229
}
12091230
}
1210-
else if (String::startsWith(temp, "/") && temp.size() > 1) {
1231+
else if (String::startsWith(temp, "/"sv) && temp.size() > 1) {
12111232
if (!(result = Find(&global, temp)).empty()) {
12121233
return result;
12131234
}

0 commit comments

Comments
 (0)