mirror of https://gitee.com/bigwinds/arangodb
Repliced some string::split by find+substr combiniation. Is more efficient.
This commit is contained in:
parent
80bb9aeff4
commit
e98c9d1281
|
@ -607,34 +607,28 @@ static void GetDocumentByIdentifier(arangodb::AqlTransaction* trx,
|
|||
searchBuilder->openObject();
|
||||
searchBuilder->add(VPackValue(StaticStrings::KeyString));
|
||||
|
||||
std::vector<std::string> parts =
|
||||
arangodb::basics::StringUtils::split(identifier, "/");
|
||||
|
||||
if (parts.size() == 1) {
|
||||
size_t pos = identifier.find('/');
|
||||
if (pos == std::string::npos) {
|
||||
searchBuilder->add(VPackValue(identifier));
|
||||
searchBuilder->close();
|
||||
} else if (parts.size() == 2) {
|
||||
} else {
|
||||
if (collectionName.empty()) {
|
||||
searchBuilder->add(VPackValue(parts[1]));
|
||||
searchBuilder->add(VPackValue(identifier.substr(pos + 1)));
|
||||
searchBuilder->close();
|
||||
collectionName = parts[0];
|
||||
} else if (parts[0] != collectionName) {
|
||||
collectionName = identifier.substr(0, pos);
|
||||
} else if (identifier.substr(0, pos) != collectionName) {
|
||||
// Reqesting an _id that cannot be stored in this collection
|
||||
if (ignoreError) {
|
||||
return;
|
||||
}
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_CROSS_COLLECTION_REQUEST);
|
||||
} else {
|
||||
searchBuilder->add(VPackValue(parts[1]));
|
||||
searchBuilder->add(VPackValue(identifier.substr(pos + 1)));
|
||||
searchBuilder->close();
|
||||
}
|
||||
} else {
|
||||
if (ignoreError) {
|
||||
return;
|
||||
}
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD);
|
||||
}
|
||||
|
||||
// TODO Operation Result is very expensive find a faster alternative
|
||||
try {
|
||||
opRes = trx->document(collectionName, searchBuilder->slice(), options);
|
||||
} catch (arangodb::basics::Exception const&) {
|
||||
|
|
|
@ -99,7 +99,7 @@ static OperationResult FetchDocumentById(arangodb::Transaction* trx,
|
|||
builder.close();
|
||||
|
||||
OperationResult opRes = trx->document(col, builder.slice(), options);
|
||||
|
||||
// TODO Operation Result is very expensive find a faster alternative
|
||||
if (opRes.failed() && opRes.code != TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) {
|
||||
THROW_ARANGO_EXCEPTION(opRes.code);
|
||||
}
|
||||
|
|
|
@ -1704,16 +1704,16 @@ static v8::Handle<v8::Value> VertexIdToData(v8::Isolate* isolate,
|
|||
Transaction* trx,
|
||||
std::string const& vertexId) {
|
||||
OperationOptions options;
|
||||
std::vector<std::string> parts =
|
||||
arangodb::basics::StringUtils::split(vertexId, "/");
|
||||
TRI_ASSERT(parts.size() == 2); // All internal _id attributes
|
||||
size_t pos = vertexId.find('/');
|
||||
TRI_ASSERT(pos != std::string::npos); // All are internal _id attributes
|
||||
|
||||
VPackBuilder builder;
|
||||
builder.openObject();
|
||||
builder.add(StaticStrings::KeyString, VPackValue(parts[1]));
|
||||
builder.add(StaticStrings::KeyString, VPackValue(vertexId.substr(pos + 1)));
|
||||
builder.close();
|
||||
|
||||
OperationResult opRes = trx->document(parts[0], builder.slice(), options);
|
||||
// TODO Operation Result is very expensive find a faster alternative
|
||||
OperationResult opRes = trx->document(vertexId.substr(0, pos), builder.slice(), options);
|
||||
|
||||
if (opRes.failed()) {
|
||||
v8::EscapableHandleScope scope(isolate);
|
||||
|
|
Loading…
Reference in New Issue