Skip to content

Commit e51297b

Browse files
author
Felipe Zimmerle
committed
Improvements on top of #1787
1 parent edb5993 commit e51297b

File tree

1 file changed

+20
-71
lines changed

1 file changed

+20
-71
lines changed

src/collection/backend/lmdb.cc

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -492,41 +492,29 @@ void LMDB::resolveMultiMatches(const std::string& var,
492492
goto end_cursor_open;
493493
}
494494

495-
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
496-
//
497-
// I don't see what's the reason of this clause
498-
//
499-
// eg:
500-
// looking for the variable: 'test', keySize will 4
501-
// found key: 'test', key.mv_size will 4
502-
// key.mv_size IS LESS than keySize+1, so we will continue?
503-
//
504-
//if (key.mv_size <= keySize + 1) {
505-
// continue;
506-
//}
507-
char *a = reinterpret_cast<char *>(key.mv_data);
508-
//
509-
// also don't understand this part
510-
//
511-
// key.mv_data will 'test', but there isn't ':' at the end,
512-
// so we will skip it?
513-
//
514-
//if (a[keySize] != ':') {
515-
// continue;
516-
//}
517-
518-
// this will never evaluate with the two statements above,
519-
// but I think this is the only required check
520-
if (strncmp(var.c_str(), a, keySize) != 0) {
521-
continue;
522-
}
523-
l->insert(l->begin(), new VariableValue(
495+
if (keySize == 0) {
496+
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
497+
l->insert(l->begin(), new VariableValue(
524498
&m_name,
525499
new std::string(reinterpret_cast<char *>(key.mv_data),
526500
key.mv_size),
527501
new std::string(reinterpret_cast<char *>(data.mv_data),
528502
data.mv_size))
529-
);
503+
);
504+
}
505+
} else {
506+
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
507+
char *a = reinterpret_cast<char *>(key.mv_data);
508+
if (strncmp(var.c_str(), a, keySize) == 0) {
509+
l->insert(l->begin(), new VariableValue(
510+
&m_name,
511+
new std::string(reinterpret_cast<char *>(key.mv_data),
512+
key.mv_size),
513+
new std::string(reinterpret_cast<char *>(data.mv_data),
514+
data.mv_size))
515+
);
516+
}
517+
}
530518
}
531519

532520
mdb_cursor_close(cursor);
@@ -549,30 +537,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
549537
MDB_cursor *cursor;
550538
size_t pos;
551539

552-
pos = var.find(":");
553-
if (pos == std::string::npos) {
554-
return;
555-
}
556-
if (var.size() < pos + 3) {
557-
return;
558-
}
559-
pos = var.find(":", pos + 2);
560-
if (pos == std::string::npos) {
561-
return;
562-
}
563-
if (var.size() < pos + 3) {
564-
return;
565-
}
566-
567-
std::string nameSpace = std::string(var, 0, pos);
568-
size_t pos2 = var.find(":", pos + 1) - pos - 1;
569-
std::string col = std::string(var, pos + 1, pos2);
570-
pos = pos2 + pos + 3;
571-
pos2 = var.size() - pos2 - pos;
572-
std::string name = std::string(var, pos, pos2);
573-
574-
size_t keySize = nameSpace.size();
575-
Utils::Regex r = Utils::Regex(name);
540+
Utils::Regex r = Utils::Regex(var);
576541

577542
rc = mdb_txn_begin(m_env, NULL, 0, &txn);
578543
lmdb_debug(rc, "txn", "resolveRegularExpression");
@@ -592,28 +557,12 @@ void LMDB::resolveRegularExpression(const std::string& var,
592557
goto end_cursor_open;
593558
}
594559

595-
std::cout << std::endl;
596560
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
597-
if (key.mv_size <= keySize) {
598-
continue;
599-
}
600561
char *a = reinterpret_cast<char *>(key.mv_data);
601-
if (a[keySize] != ':') {
602-
continue;
603-
}
604-
std::string ns = std::string(a, keySize);
605-
if (ns != nameSpace) {
606-
continue;
607-
}
608-
609-
std::string content = std::string(a, keySize + 1,
610-
key.mv_size - keySize - 1);
611-
612-
int ret = Utils::regex_search(content, r);
562+
int ret = Utils::regex_search(a, r);
613563
if (ret <= 0) {
614564
continue;
615565
}
616-
617566
VariableValue *v = new VariableValue(
618567
new std::string(reinterpret_cast<char *>(key.mv_data),
619568
key.mv_size),

0 commit comments

Comments
 (0)