Merge pull request #3426 from Clikengo/fix-3424

fix ClientVersionRef versionString should be passed by ref
This commit is contained in:
A.J. Beamon 2020-07-02 08:06:04 -07:00 committed by GitHub
commit b7189f5168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 23 deletions

View File

@ -94,23 +94,15 @@ struct ClientVersionRef {
ClientVersionRef(Arena &arena, ClientVersionRef const& cv) : clientVersion(arena, cv.clientVersion), sourceVersion(arena, cv.sourceVersion), protocolVersion(arena, cv.protocolVersion) {}
ClientVersionRef(StringRef clientVersion, StringRef sourceVersion, StringRef protocolVersion) : clientVersion(clientVersion), sourceVersion(sourceVersion), protocolVersion(protocolVersion) {}
ClientVersionRef(std::string versionString) {
size_t index = versionString.find(",");
if(index == versionString.npos) {
ClientVersionRef(StringRef versionString) {
std::vector<StringRef> parts = versionString.splitAny(LiteralStringRef(","));
if (parts.size() != 3) {
initUnknown();
return;
}
clientVersion = StringRef((uint8_t*)&versionString[0], index);
size_t nextIndex = versionString.find(",", index+1);
if(index == versionString.npos) {
initUnknown();
return;
}
sourceVersion = StringRef((uint8_t*)&versionString[index+1], nextIndex-(index+1));
protocolVersion = StringRef((uint8_t*)&versionString[nextIndex+1], versionString.length()-(nextIndex+1));
clientVersion = parts[0];
sourceVersion = parts[1];
protocolVersion = parts[2];
}
void initUnknown() {

View File

@ -1378,7 +1378,7 @@ void ClientInfo::loadProtocolVersion() {
}
char *next;
std::string protocolVersionStr = ClientVersionRef(version).protocolVersion.toString();
std::string protocolVersionStr = ClientVersionRef(StringRef(version)).protocolVersion.toString();
protocolVersion = ProtocolVersion(strtoull(protocolVersionStr.c_str(), &next, 16));
ASSERT(protocolVersion.version() != 0 && protocolVersion.version() != ULLONG_MAX);

View File

@ -1334,14 +1334,9 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
ASSERT(value.present());
Standalone<VectorRef<ClientVersionRef>> supportedVersions;
std::string versionString = value.get().toString();
size_t index = 0;
size_t nextIndex = 0;
while(nextIndex != versionString.npos) {
nextIndex = versionString.find(';', index);
supportedVersions.push_back_deep(supportedVersions.arena(), ClientVersionRef(versionString.substr(index, nextIndex-index)));
index = nextIndex + 1;
std::vector<StringRef> supportedVersionsStrings = value.get().splitAny(LiteralStringRef(";"));
for (StringRef versionString: supportedVersionsStrings) {
supportedVersions.push_back_deep(supportedVersions.arena(), ClientVersionRef(versionString));
}
ASSERT(supportedVersions.size() > 0);

View File

@ -599,6 +599,15 @@ public:
return dst + length;
}
std::vector<StringRef> splitAny(StringRef sep) const {
StringRef r = *this;
std::vector<StringRef> tokens;
while (r.size()) {
tokens.push_back(r.eatAny(sep, nullptr));
}
return tokens;
}
private:
// Unimplemented; blocks conversion through std::string
StringRef( char* );