10000 speeds up some use cases of AQL CONTAINS · aa10000/arangodb@10398b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10398b2

Browse files
committed
speeds up some use cases of AQL CONTAINS
1 parent 9ab9f17 commit 10398b2

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

arangod/Aql/Functions.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static AqlValue ExtractFunctionParameterValue(
212212
// parameter out of range
213213
return AqlValue();
214214
}
215-
return parameters.at(position);
215+
return parameters[position];
216216
}
217217

218218
/// @brief extra a collection name from an AqlValue
@@ -1109,6 +1109,8 @@ AqlValue Functions::Contains(arangodb::aql::Query* query,
11091109
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
11101110
AqlValue search = ExtractFunctionParameterValue(trx, parameters, 1);
11111111
AqlValue returnIndex = ExtractFunctionParameterValue(trx, parameters, 2);
1112+
1113+
bool const willReturnIndex = returnIndex.toBoolean();
11121114

11131115
int result = -1; // default is "not found"
11141116
{
@@ -1126,28 +1128,34 @@ AqlValue Functions::Contains(arangodb::aql::Query* query,
11261128
char const* found = static_cast<char const*>(memmem(buffer->c_str(), valueLength, buffer->c_str() + searchOffset, searchLength));
11271129

11281130
if (found != nullptr) {
1129-
// find offset into string
1130-
int bytePosition = static_cast<int>(found - buffer->c_str());
1131-
char const* p = buffer->c_str();
1132-
int pos = 0;
1133-
while (pos < bytePosition) {
1134-
unsigned char c = static_cast<unsigned char>(*p);
1135-
if (c < 128) {
1136-
++pos;
1137-
} else if (c < 224) {
1138-
pos += 2;
1139-
} else if (c < 240) {
1140-
pos += 3;
1141-
} else if (c < 248) {
1142-
pos += 4;
1131+
if (willReturnIndex) {
1132+
// find offset into string
1133+
int bytePosition = static_cast<int>(found - buffer->c_str());
1134+
char const* p = buffer->c_str();
1135+
int pos = 0;
1136+
while (pos < bytePosition) {
1137+
unsigned char c = static_cast<unsigned char>(*p);
1138+
if (c < 128) {
1139+
++pos;
1140+
} else if (c < 224) {
1141+
pos += 2;
1142+
} else if (c < 240) {
1143+
pos += 3;
1144+
} else if (c < 248) {
1145+
pos += 4;
1146+
}
11431147
}
1148+
result = pos;
1149+
} else {
1150+
// fake result position, but it does not matter as it will
1151+
// only be compared to -1 later
1152+
result = 0;
11441153
}
1145-
result = pos;
11461154
}
11471155
}
11481156
}
11491157

1150-
if (returnIndex.toBoolean()) {
1158+
if (willReturnIndex) {
11511159
// return numeric value
11521160
return NumberValue(trx, result);
11531161
}

0 commit comments

Comments
 (0)
0