Skip to content

Commit 4b8e06e

Browse files
authored
fix coredump (#15497) (#15659)
1 parent d14f770 commit 4b8e06e

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

ydb/library/workload/tpch/driver.cpp

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,69 @@
33
#include <util/generic/map.h>
44
#include <util/string/cast.h>
55

6-
struct TDist {
7-
TVector<set_member> Members;
8-
long Max = 0;
9-
};
10-
11-
extern "C" void ReadDistFromResource(const char* name, distribution* target) {
12-
static auto distributions = [] () {
13-
TMap<TStringBuf, TDist> result;
14-
static const auto resource = NResource::Find("dists.dss");
15-
TStringBuf in(resource);
16-
TStringBuf line;
17-
TDist* dist = nullptr;
6+
class TDistributions {
7+
public:
8+
TDistributions() {
9+
const auto resource = NResource::Find("dists.dss");
10+
TStringInput in(resource);
11+
TString line;
12+
TDists::iterator dist = Dists.end();
1813
while (in.ReadLine(line)) {
1914
if (line.empty() || line.find('#') != TStringBuf::npos) {
2015
continue;
2116
}
22-
if (!dist) {
17+
if (dist == Dists.end()) {
2318
constexpr TStringBuf prefix = "begin";
24-
if (to_lower(TString(line.substr(0, prefix.length()))) == prefix) {
19+
if (to_lower(line.substr(0, prefix.length())) == prefix) {
2520
const auto pos = line.find_first_of("\t ");
2621
if (pos != TStringBuf::npos) {
27-
dist = &result[line.substr(pos + 1)];
22+
const TString key(line.substr(pos + 1));
23+
dist = Dists.emplace(key, TDist()).first;
2824
}
2925
}
3026
} else {
3127
constexpr TStringBuf prefix = "end";
32-
if (to_lower(TString(line.substr(0, prefix.length()))) == prefix) {
33-
dist = nullptr;
28+
if (to_lower(line.substr(0, prefix.length())) == prefix) {
29+
dist = Dists.end();
3430
continue;
3531
}
3632
TStringBuf token, weightStr;
37-
line.Split('|', token, weightStr);
33+
TStringBuf(line).Split('|', token, weightStr);
3834
while(weightStr.SkipPrefix(" "));
3935
while(weightStr.ChopSuffix(" "));
4036
long weight = FromString(weightStr);
4137
if (to_lower(TString(token)) == "count") {
42-
dist->Members.reserve(weight);
38+
dist->second.Members.reserve(weight);
4339
} else {
44-
dist->Max += weight;
45-
dist->Members.emplace_back();
46-
dist->Members.back().weight = dist->Max;
47-
dist->Members.back().text = const_cast<char*>(token.data());
48-
dist->Members.back().text[token.length()] = '\0';
40+
dist->second.Max += weight;
41+
dist->second.Members.emplace_back();
42+
Strings.emplace_back(token);
43+
dist->second.Members.back().weight = dist->second.Max;
44+
dist->second.Members.back().text = Strings.back().begin();
4945
}
5046
}
5147
}
52-
return result;
53-
}();
48+
}
5449

55-
if (auto* dist = MapFindPtr(distributions, name)) {
56-
target->count = dist->Members.size();
57-
target->list = dist->Members.data();
58-
target->permute = nullptr;
59-
target->max = dist->Max;
50+
void Fill(const char* name, distribution* target) {
51+
if (auto* dist = MapFindPtr(Dists, name)) {
52+
target->count = dist->Members.size();
53+
target->list = dist->Members.data();
54+
target->permute = nullptr;
55+
target->max = dist->Max;
56+
}
6057
}
58+
59+
private:
60+
struct TDist {
61+
TVector<set_member> Members;
62+
long Max = 0;
63+
};
64+
using TDists = TMap<TString, TDist>;
65+
TVector<TString> Strings;
66+
TDists Dists;
67+
};
68+
69+
extern "C" void ReadDistFromResource(const char* name, distribution* target) {
70+
Singleton<TDistributions>()->Fill(name, target);
6171
}

0 commit comments

Comments
 (0)