8000 use std::vector · ezhangle/arangodb@b331c22 · GitHub
[go: up one dir, main page]

Skip to content

Commit b331c22

Browse files
committed
use std::vector
1 parent 6d43950 commit b331c22

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

arangod/V8Server/v8-vocindex.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,25 +1434,19 @@ static void JS_GetIndexesVocbaseCol (const v8::FunctionCallbackInfo<v8::Value>&
14341434
std::string const& collectionName = std::string(collection->_name);
14351435

14361436
// get list of indexes
1437-
TRI_vector_pointer_t* indexes = TRI_IndexesDocumentCollection(document);
1437+
auto&& indexes = TRI_IndexesDocumentCollection(document);
14381438

14391439
trx.finish(res);
14401440
// READ-LOCK end
14411441

1442-
if (indexes == nullptr) {
1443-
TRI_V8_THROW_EXCEPTION_MEMORY();
1444-
}
1445-
1446-
size_t const n = indexes->_length;
1442+
size_t const n = indexes.size();
14471443
v8::Handle<v8::Array> result = v8::Array::New(isolate, static_cast<int>(n));
14481444

14491445
for (size_t i = 0; i < n; ++i) {
1450-
auto idx = static_cast<TRI_json_t*>(indexes->_buffer[i]);
1446+
auto const& idx = indexes[i];
14511447

1452-
result->Set(static_cast<uint32_t>(i), IndexRep(isolate, collectionName, idx));
1453-
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, idx);
1448+
result->Set(static_cast<uint32_t>(i), IndexRep(isolate, collectionName, idx.json()));
14541449
}
1455-
TRI_FreeVectorPointer(TRI_UNKNOWN_MEM_ZONE, indexes);
14561450

14571451
TRI_V8_RETURN(result);
14581452
TRI_V8_TRY_CATCH_END

arangod/VocBase/document-collection.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,22 +3538,20 @@ int TRI_SaveIndex (TRI_document_collection_t* document,
35383538
/// the caller must have read-locked the underlying collection!
35393539
////////////////////////////////////////////////////////////////////////////////
35403540

3541-
TRI_vector_pointer_t* TRI_IndexesDocumentCollection (TRI_document_collection_t* document) {
3542-
TRI_vector_pointer_t* vector = static_cast<TRI_vector_pointer_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_vector_pointer_t), false));
3541+
std::vector<triagens::basics::Json> TRI_IndexesDocumentCollection (TRI_document_collection_t* document) {
3542+
auto const& indexes = document->allIndexes();
35433543

3544-
if (vector == nullptr) {
3545-
return nullptr;
3546-
}
3547-
3548-
TRI_InitVectorPointer(vector, TRI_UNKNOWN_MEM_ZONE);
3544+
std::vector<triagens::basics::Json> result;
3545+
result.reserve(indexes.size());
35493546

3550-
for (auto const& idx : document->allIndexes()) {
3547+
for (auto const& idx : indexes) {
35513548
auto json = idx->toJson(TRI_UNKNOWN_MEM_ZONE);
35523549

3553-
TRI_PushBackVectorPointer(vector, json.steal());
3550+
// shouldn't fail because of reserve
3551+
result.emplace_back(json);
35543552
}
35553553

3556-
return vector;
3554+
return result;
35573555
}
35583556

35593557
////////////////////////////////////////////////////////////////////////////////

arangod/VocBase/document-collection.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
struct TRI_cap_constraint_s;
5353
struct TRI_document_edge_s;
5454
struct TRI_json_t;
55-
struct TRI_vector_pointer_s;
5655

5756
class VocShaper;
5857

@@ -850,7 +849,7 @@ int TRI_SaveIndex (TRI_document_collection_t*,
850849
/// the caller must have read-locked the underyling collection!
851850
////////////////////////////////////////////////////////////////////////////////
852851

853-
struct TRI_vector_pointer_s* TRI_IndexesDocumentCollection (TRI_document_collection_t*);
852+
std::vector<triagens::basics::Json> TRI_IndexesDocumentCollection (TRI_document_collection_t*);
854853

855854
////////////////////////////////////////////////////////////////////////////////
856855
/// @brief drops an index, including index file removal and replication

0 commit comments

Comments
 (0)
0