1
0
Fork 0

"privatized" TRI_vector_t internals.

This allows changing the internals of TRI_vector_t structs in order to make the struct smaller.
On 64 bits, the size of TRI_vector_t is reduced from 48 bytes to 28 bytes.
TRI_json_t does benefit from this, as its biggest component is a TRI_vector_t.
This commit is contained in:
Jan Steemann 2015-05-05 10:31:02 +02:00
parent ca8341a157
commit a007a867ee
47 changed files with 389 additions and 370 deletions

View File

@ -68,14 +68,6 @@ struct CVectorSetup {
BOOST_FIXTURE_TEST_SUITE(CVectorTest, CVectorSetup)
////////////////////////////////////////////////////////////////////////////////
/// @brief test size
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_size) {
BOOST_CHECK_EQUAL((size_t) 5 * sizeof(void*), sizeof(TRI_vector_t));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test length after vector initialisation
////////////////////////////////////////////////////////////////////////////////
@ -83,7 +75,7 @@ BOOST_AUTO_TEST_CASE (tst_size) {
BOOST_AUTO_TEST_CASE (tst_length_init) {
VECTOR_INIT
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(true, TRI_EmptyVector(&v1));
VECTOR_DESTROY
@ -101,15 +93,15 @@ BOOST_AUTO_TEST_CASE (tst_length_insert) {
int p1 = 1;
int p2 = 2;
TRI_PushBackVector(&v1, &p1);
BOOST_CHECK_EQUAL((size_t) 1, v1._length);
BOOST_CHECK_EQUAL((size_t) 1, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
TRI_PushBackVector(&v1, &p1);
BOOST_CHECK_EQUAL((size_t) 2, v1._length);
BOOST_CHECK_EQUAL((size_t) 2, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
TRI_PushBackVector(&v1, &p2);
BOOST_CHECK_EQUAL((size_t) 3, v1._length);
BOOST_CHECK_EQUAL((size_t) 3, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
VECTOR_DESTROY
@ -128,24 +120,24 @@ BOOST_AUTO_TEST_CASE (tst_length_insert_remove) {
int p2 = 2;
int p3 = 3;
TRI_PushBackVector(&v1, &p1);
BOOST_CHECK_EQUAL((size_t) 1, v1._length);
BOOST_CHECK_EQUAL((size_t) 1, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(true, TRI_EmptyVector(&v1));
TRI_PushBackVector(&v1, &p2);
TRI_PushBackVector(&v1, &p3);
BOOST_CHECK_EQUAL((size_t) 2, v1._length);
BOOST_CHECK_EQUAL((size_t) 2, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 1, v1._length);
BOOST_CHECK_EQUAL((size_t) 1, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(true, TRI_EmptyVector(&v1));
VECTOR_DESTROY
@ -166,14 +158,14 @@ BOOST_AUTO_TEST_CASE (tst_length_clear) {
TRI_PushBackVector(&v1, &p1);
TRI_PushBackVector(&v1, &p2);
TRI_PushBackVector(&v1, &p3);
BOOST_CHECK_EQUAL((size_t) 3, v1._length);
BOOST_CHECK_EQUAL((size_t) 3, TRI_LengthVector(&v1));
TRI_ClearVector(&v1);
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(true, TRI_EmptyVector(&v1));
TRI_PushBackVector(&v1, &p2);
BOOST_CHECK_EQUAL((size_t) 1, v1._length);
BOOST_CHECK_EQUAL((size_t) 1, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(false, TRI_EmptyVector(&v1));
VECTOR_DESTROY
@ -192,7 +184,7 @@ BOOST_AUTO_TEST_CASE (tst_remove_invalid1) {
TRI_RemoveVector(&v1, -1); // invalid position
TRI_RemoveVector(&v1, 99); // invalid position
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(true, TRI_EmptyVector(&v1));
VECTOR_DESTROY
@ -331,7 +323,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_duplicate) {
TRI_PushBackVector(&v1, &b);
TRI_PushBackVector(&v1, &b);
BOOST_CHECK_EQUAL((size_t) 6, v1._length);
BOOST_CHECK_EQUAL((size_t) 6, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 2));
@ -357,7 +349,7 @@ BOOST_AUTO_TEST_CASE (tst_remove_duplicate) {
TRI_PushBackVector(&v1, &b);
TRI_PushBackVector(&v1, &b);
BOOST_CHECK_EQUAL((size_t) 5, v1._length);
BOOST_CHECK_EQUAL((size_t) 5, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 2));
@ -367,7 +359,7 @@ BOOST_AUTO_TEST_CASE (tst_remove_duplicate) {
TRI_RemoveVector(&v1, 4);
TRI_RemoveVector(&v1, 0);
TRI_RemoveVector(&v1, 1);
BOOST_CHECK_EQUAL((size_t) 2, v1._length);
BOOST_CHECK_EQUAL((size_t) 2, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 1));
@ -397,7 +389,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
TRI_PushBackVector(&v1, &a);
TRI_PushBackVector(&v1, &a);
BOOST_CHECK_EQUAL((size_t) 10, v1._length);
BOOST_CHECK_EQUAL((size_t) 10, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 2));
@ -410,7 +402,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 9));
TRI_RemoveVector(&v1, 4);
BOOST_CHECK_EQUAL((size_t) 9, v1._length);
BOOST_CHECK_EQUAL((size_t) 9, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 2));
@ -422,7 +414,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 8));
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 8, v1._length);
BOOST_CHECK_EQUAL((size_t) 8, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 2));
@ -433,7 +425,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 7));
TRI_RemoveVector(&v1, 7);
BOOST_CHECK_EQUAL((size_t) 7, v1._length);
BOOST_CHECK_EQUAL((size_t) 7, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 2));
@ -444,7 +436,7 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
TRI_RemoveVector(&v1, 0);
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 5, v1._length);
BOOST_CHECK_EQUAL((size_t) 5, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 2));
@ -453,19 +445,19 @@ BOOST_AUTO_TEST_CASE (tst_push_back_remove) {
TRI_RemoveVector(&v1, 1);
TRI_RemoveVector(&v1, 1);
BOOST_CHECK_EQUAL((size_t) 3, v1._length);
BOOST_CHECK_EQUAL((size_t) 3, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 2));
TRI_RemoveVector(&v1, 1);
BOOST_CHECK_EQUAL((size_t) 2, v1._length);
BOOST_CHECK_EQUAL((size_t) 2, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 1));
TRI_RemoveVector(&v1, 1);
TRI_RemoveVector(&v1, 0);
BOOST_CHECK_EQUAL((size_t) 0, v1._length);
BOOST_CHECK_EQUAL((size_t) 0, TRI_LengthVector(&v1));
VECTOR_DESTROY
}
@ -487,7 +479,7 @@ BOOST_AUTO_TEST_CASE (tst_set) {
TRI_PushBackVector(&v1, &c);
TRI_PushBackVector(&v1, &d);
BOOST_CHECK_EQUAL((size_t) 4, v1._length);
BOOST_CHECK_EQUAL((size_t) 4, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 2));
@ -500,7 +492,7 @@ BOOST_AUTO_TEST_CASE (tst_set) {
TRI_SetVector(&v1, 2, &b);
TRI_SetVector(&v1, 3, &a);
BOOST_CHECK_EQUAL((size_t) 4, v1._length);
BOOST_CHECK_EQUAL((size_t) 4, TRI_LengthVector(&v1));
BOOST_CHECK_EQUAL(4, *(int*) TRI_AtVector(&v1, 0));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(&v1, 1));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(&v1, 2));
@ -539,7 +531,7 @@ BOOST_AUTO_TEST_CASE (tst_copy) {
VECTOR_DESTROY
BOOST_CHECK_EQUAL((size_t) 4, v2->_length);
BOOST_CHECK_EQUAL((size_t) 4, TRI_LengthVector(v2));
BOOST_CHECK_EQUAL(1, *(int*) TRI_AtVector(v2, 0));
BOOST_CHECK_EQUAL(2, *(int*) TRI_AtVector(v2, 1));
BOOST_CHECK_EQUAL(3, *(int*) TRI_AtVector(v2, 2));

View File

@ -491,7 +491,7 @@ v8::Handle<v8::Value> AqlValue::toV8Partial (v8::Isolate* isolate,
TRI_json_t const* json = _json->json();
if (TRI_IsObjectJson(json)) {
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
v8::Handle<v8::Object> result = v8::Object::New(isolate);

View File

@ -2215,7 +2215,7 @@ AstNode* Ast::nodeFromJson (TRI_json_t const* json) {
if (json->_type == TRI_JSON_ARRAY) {
auto node = createNodeArray();
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthArrayJson(json);
for (size_t i = 0; i < n; ++i) {
node->addMember(nodeFromJson(static_cast<TRI_json_t const*>(TRI_AddressVector(&json->_value._objects, i))));
@ -2226,7 +2226,7 @@ AstNode* Ast::nodeFromJson (TRI_json_t const* json) {
if (json->_type == TRI_JSON_OBJECT) {
auto node = createNodeObject();
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
auto key = static_cast<TRI_json_t const*>(TRI_AddressVector(&json->_value._objects, i));

View File

@ -78,7 +78,8 @@ void BindParameters::process () {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_BIND_PARAMETERS_INVALID);
}
size_t const n = _json->_value._objects._length;
size_t const n = TRI_LengthVector(&_json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* key = static_cast<TRI_json_t const*>(TRI_AtVector(&_json->_value._objects, i));

View File

@ -2196,7 +2196,7 @@ bool IndexRangeBlock::setupHashIndexSearchValue (IndexAndCondition const& range)
TRI_shaper_t* shaper = _collection->documentCollection()->getShaper();
size_t const n = hashIndex->_paths._length;
size_t const n = TRI_LengthVector(&hashIndex->_paths);
TRI_ASSERT(_hashIndexSearchValue._values == nullptr); // to prevent leak
_hashIndexSearchValue._length = 0;

View File

@ -290,7 +290,7 @@ AqlValue Functions::Length (triagens::aql::Query*,
case TRI_JSON_OBJECT: {
// return number of attributes
length = json->_value._objects._length / 2;
length = TRI_LengthVector(&json->_value._objects) / 2;
break;
}
@ -392,7 +392,7 @@ AqlValue Functions::Unset (triagens::aql::Query* query,
// create result object
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthVector(&valueJson->_value._objects);
size_t size;
if (names.size() >= n / 2) {
@ -456,7 +456,7 @@ AqlValue Functions::Keep (triagens::aql::Query* query,
}
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthVector(&valueJson->_value._objects);
for (size_t i = 0; i < n; i += 2) {
auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&valueJson->_value._objects, i));
@ -584,7 +584,7 @@ AqlValue Functions::Min (triagens::aql::Query* query,
}
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthArrayJson(valueJson);
TRI_json_t const* minValue = nullptr;;
for (size_t i = 0; i < n; ++i) {
@ -630,7 +630,7 @@ AqlValue Functions::Max (triagens::aql::Query* query,
}
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthArrayJson(valueJson);
TRI_json_t const* maxValue = nullptr;;
for (size_t i = 0; i < n; ++i) {
@ -676,7 +676,7 @@ AqlValue Functions::Sum (triagens::aql::Query* query,
}
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthArrayJson(valueJson);
double sum = 0.0;
for (size_t i = 0; i < n; ++i) {
@ -723,7 +723,7 @@ AqlValue Functions::Average (triagens::aql::Query* query,
}
TRI_json_t const* valueJson = value.json();
size_t const n = valueJson->_value._objects._length;
size_t const n = TRI_LengthArrayJson(valueJson);
double sum = 0.0;
size_t count = 0;

View File

@ -1499,7 +1499,8 @@ int ClusterInfo::ensureIndexCoordinator (string const& databaseName,
return setErrormsg(TRI_ERROR_INTERNAL, errorMsg);
}
for (size_t i = 0; i < indexes->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(indexes);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* other = TRI_LookupArrayJson(indexes, i);
if (! TRI_CheckSameValueJson(TRI_LookupObjectJson(json, "type"),
@ -1614,7 +1615,8 @@ int ClusterInfo::ensureIndexCoordinator (string const& databaseName,
break;
}
for (size_t i = 0; i < indexes->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(indexes);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(indexes, i);
// check for errors
@ -1735,7 +1737,8 @@ int ClusterInfo::dropIndexCoordinator (string const& databaseName,
bool found = false;
// copy remaining indexes back into collection
for (size_t i = 0; i < indexes->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(indexes);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(indexes, i);
TRI_json_t const* id = TRI_LookupObjectJson(v, "id");
TRI_json_t const* type = TRI_LookupObjectJson(v, "type");
@ -1808,8 +1811,10 @@ int ClusterInfo::dropIndexCoordinator (string const& databaseName,
TRI_json_t const* indexes = TRI_LookupObjectJson(json, "indexes");
if (TRI_IsArrayJson(indexes)) {
for (size_t i = 0; i < indexes->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(indexes);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(indexes, i);
if (TRI_IsObjectJson(v)) {
TRI_json_t const* k = TRI_LookupObjectJson(v, "id");
if (TRI_IsStringJson(k) && idString == string(k->_value._string.data)) {

View File

@ -250,8 +250,9 @@ namespace triagens {
int numberOfShards () const {
TRI_json_t* const node = triagens::basics::JsonHelper::getObjectElement(_json, "shards");
if (TRI_IsObjectJson(node)) {
return (int) (node->_value._objects._length / 2);
return (int) (TRI_LengthVector(&node->_value._objects) / 2);
}
return 0;
}

View File

@ -247,7 +247,8 @@ int usersOnCoordinator (std::string const& dbname,
TRI_json_t const* r = TRI_LookupObjectJson(json, "result");
if (TRI_IsArrayJson(r)) {
for (size_t i = 0; i < r->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(r);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* p = TRI_LookupArrayJson(r, i);
if (TRI_IsObjectJson(p)) {
@ -1344,7 +1345,8 @@ TRI_vector_pointer_t* getIndexesCoordinator (string const& databaseName,
TRI_json_t const* json = (*c).getIndexes();
if (TRI_IsArrayJson(json)) {
for (size_t i = 0; i < json->_value._objects._length; ++i) {
size_t const n = TRI_LengthArrayJson(json);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(json, i);
if (TRI_IsObjectJson(v)) {
@ -1390,7 +1392,9 @@ TRI_vector_pointer_t* getIndexesCoordinator (string const& databaseName,
value = TRI_LookupObjectJson(v, "fields");
if (TRI_IsArrayJson(value)) {
for (size_t j = 0; j < value->_value._objects._length; ++j) {
size_t const n = TRI_LengthArrayJson(value);
for (size_t j = 0; j < n; ++j) {
TRI_json_t const* f = TRI_LookupArrayJson(value, j);
if (TRI_IsStringJson(f)) {

View File

@ -639,7 +639,7 @@ bool HeartbeatThread::fetchUsers (TRI_vocbase_t* vocbase) {
// we were able to read from the _users collection
TRI_ASSERT(TRI_IsArrayJson(json));
if (json->_value._objects._length == 0) {
if (TRI_LengthArrayJson(json) == 0) {
// no users found, now insert initial default user
TRI_InsertInitialAuthInfo(vocbase);
}

View File

@ -47,7 +47,7 @@ struct TRI_hash_index_element_multi_s;
////////////////////////////////////////////////////////////////////////////////
static inline size_t NumPaths (TRI_hash_index_t const* idx) {
return idx->_paths._length;
return TRI_LengthVector(&idx->_paths);
}
////////////////////////////////////////////////////////////////////////////////
@ -425,9 +425,10 @@ static TRI_json_t* JsonHashIndex (TRI_index_t const* idx) {
// Allocate sufficent memory for the field list
// ..........................................................................
char const** fieldList = static_cast<char const**>(TRI_Allocate(TRI_CORE_MEM_ZONE, (sizeof(char*) * hashIndex->_paths._length) , false));
size_t const n = TRI_LengthVector(&hashIndex->_paths);
char const** fieldList = static_cast<char const**>(TRI_Allocate(TRI_CORE_MEM_ZONE, (sizeof(char*) * n) , false));
for (size_t j = 0; j < hashIndex->_paths._length; ++j) {
for (size_t j = 0; j < n; ++j) {
TRI_shape_pid_t shape = *((TRI_shape_pid_t*) TRI_AtVector(&hashIndex->_paths, j));
TRI_shape_path_t const* path = document->getShaper()->lookupAttributePathByPid(document->getShaper(), shape); // ONLY IN INDEX, PROTECTED by RUNTIME
@ -451,7 +452,7 @@ static TRI_json_t* JsonHashIndex (TRI_index_t const* idx) {
TRI_json_t* fields = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);
for (size_t j = 0; j < hashIndex->_paths._length; ++j) {
for (size_t j = 0; j < n; ++j) {
TRI_PushBack3ArrayJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, fieldList[j], strlen(fieldList[j])));
}
@ -640,12 +641,10 @@ TRI_index_t* TRI_CreateHashIndex (TRI_document_collection_t* document,
int res;
if (unique) {
res = TRI_InitHashArray(&hashIndex->_hashArray,
hashIndex->_paths._length);
res = TRI_InitHashArray(&hashIndex->_hashArray, TRI_LengthVector(&hashIndex->_paths));
}
else {
res = TRI_InitHashArrayMulti(&hashIndex->_hashArrayMulti,
hashIndex->_paths._length);
res = TRI_InitHashArrayMulti(&hashIndex->_hashArrayMulti, TRI_LengthVector(&hashIndex->_paths));
}
// oops, out of memory?

View File

@ -421,7 +421,7 @@ int InitialSyncer::applyCollectionDump (TRI_transaction_collection_t* trxCollect
TRI_json_t const* doc = nullptr;
TRI_voc_rid_t rid = 0;
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* element = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
@ -808,7 +808,7 @@ int InitialSyncer::handleCollection (TRI_json_t const* parameters,
if (res == TRI_ERROR_NO_ERROR) {
// now create indexes
size_t const n = indexes->_value._objects._length;
size_t const n = TRI_LengthVector(&indexes->_value._objects);
if (n > 0) {
string const progress = "creating indexes for " + collectionMsg;
@ -940,7 +940,7 @@ int InitialSyncer::handleInventoryResponse (TRI_json_t const* json,
int InitialSyncer::iterateCollections (TRI_json_t const* collections,
string& errorMsg,
sync_phase_e phase) {
size_t const n = collections->_value._objects._length;
size_t const n = TRI_LengthVector(&collections->_value._objects);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* collection = static_cast<TRI_json_t const*>(TRI_AtVector(&collections->_value._objects, i));

View File

@ -177,8 +177,11 @@ triagens::basics::Json RestCursorHandler::buildOptions (TRI_json_t const* json)
}
attribute = getAttribute("options");
if (TRI_IsObjectJson(attribute)) {
for (size_t i = 0; i < attribute->_value._objects._length; i += 2) {
size_t const n = TRI_LengthVector(&attribute->_value._objects);
for (size_t i = 0; i < n; i += 2) {
auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&attribute->_value._objects, i));
auto value = static_cast<TRI_json_t const*>(TRI_AtVector(&attribute->_value._objects, i + 1));

View File

@ -882,7 +882,7 @@ bool RestImportHandler::createFromJson (string const& type) {
return false;
}
size_t const n = documents->_value._objects._length;
size_t const n = TRI_LengthArrayJson(documents);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* json = static_cast<TRI_json_t const*>(TRI_AtVector(&documents->_value._objects, i));
@ -1461,9 +1461,9 @@ TRI_json_t* RestImportHandler::createJsonObject (TRI_json_t const* keys,
return nullptr;
}
size_t const n = keys->_value._objects._length;
size_t const n = TRI_LengthArrayJson(keys);
if (n != values->_value._objects._length) {
if (n != TRI_LengthArrayJson(values)) {
errorMsg = positionise(lineNumber) + "wrong number of JSON values";
return nullptr;
}
@ -1497,7 +1497,7 @@ bool RestImportHandler::checkKeys (TRI_json_t const* keys) const {
return false;
}
size_t const n = keys->_value._objects._length;
size_t const n = TRI_LengthArrayJson(keys);
if (n == 0) {
return false;

View File

@ -1232,7 +1232,7 @@ void RestReplicationHandler::handleCommandInventory () {
TRI_ASSERT(JsonHelper::isArray(collections));
// sort collections by type, then name
size_t const n = collections->_value._objects._length;
size_t const n = TRI_LengthArrayJson(collections);
if (n > 1) {
// sort by collection type (vertices before edges), then name
@ -1927,7 +1927,8 @@ int RestReplicationHandler::processRestoreIndexes (TRI_json_t const* collection,
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
size_t const n = indexes->_value._objects._length;
size_t const n = TRI_LengthArrayJson(indexes);
if (n == 0) {
// nothing to do
return TRI_ERROR_NO_ERROR;
@ -2030,7 +2031,7 @@ int RestReplicationHandler::processRestoreIndexesCoordinator (
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
const size_t n = indexes->_value._objects._length;
const size_t n = TRI_LengthArrayJson(indexes);
if (n == 0) {
// nothing to do
return TRI_ERROR_NO_ERROR;
@ -2251,7 +2252,7 @@ int RestReplicationHandler::processRestoreDataBatch (CollectionNameResolver cons
TRI_voc_rid_t rid = 0;
TRI_json_t const* doc = nullptr;
const size_t n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* element = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
@ -2488,7 +2489,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () {
TRI_json_t const* doc = nullptr;
TRI_replication_operation_e type = REPLICATION_INVALID;
const size_t n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* element = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
@ -3077,8 +3078,8 @@ void RestReplicationHandler::handleCommandSync () {
std::unordered_map<string, bool> restrictCollections;
TRI_json_t* restriction = JsonHelper::getObjectElement(json, "restrictCollections");
if (restriction != nullptr && restriction->_type == TRI_JSON_ARRAY) {
size_t const n = restriction->_value._objects._length;
if (TRI_IsArrayJson(restriction)) {
size_t const n = TRI_LengthArrayJson(restriction);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* cname = static_cast<TRI_json_t const*>(TRI_AtVector(&restriction->_value._objects, i));

View File

@ -268,7 +268,7 @@ static bool SkiplistHasNextIterationCallback (TRI_skiplist_iterator_t const* ite
// if we have more intervals than the one we are currently working
// on then of course we have a next doc, since intervals are nonempty.
// ...........................................................................
if (iterator->_intervals._length - 1 > iterator->_currentInterval) {
if (TRI_LengthVector(&iterator->_intervals) - 1 > iterator->_currentInterval) {
return true;
}
@ -371,7 +371,7 @@ static TRI_skiplist_index_element_t* SkiplistNextIterationCallback (
// Note that _cursor can be nullptr here!
break; // we found a next one
}
if (iterator->_currentInterval == (iterator->_intervals._length - 1)) {
if (iterator->_currentInterval == (TRI_LengthVector(&iterator->_intervals) - 1)) {
iterator->_cursor = nullptr; // exhausted
return nullptr;
}
@ -630,8 +630,10 @@ static void SkiplistIndex_findHelper (SkiplistIndex* skiplistIndex,
SkiplistIndex_findHelper(skiplistIndex,shapeList, logicalOperator->_left, &leftResult);
SkiplistIndex_findHelper(skiplistIndex,shapeList, logicalOperator->_right, &rightResult);
for (size_t i = 0; i < leftResult._length; ++i) {
for (size_t j = 0; j < rightResult._length; ++j) {
size_t nl = TRI_LengthVector(&leftResult);
size_t nr = TRI_LengthVector(&rightResult);
for (size_t i = 0; i < nl; ++i) {
for (size_t j = 0; j < nr; ++j) {
auto tempLeftInterval = static_cast<TRI_skiplist_iterator_interval_t*>(TRI_AddressVector(&leftResult, i));
auto tempRightInterval = static_cast<TRI_skiplist_iterator_interval_t*>(TRI_AddressVector(&rightResult, j));

View File

@ -345,7 +345,7 @@ void ExportCursor::dump (triagens::basics::StringBuffer& buffer) {
TRI_json_t* obj = json.json();
TRI_ASSERT(TRI_IsObjectJson(obj));
size_t const n = obj->_value._objects._length;
size_t const n = TRI_LengthVector(&obj->_value._objects);
size_t j = 0;
for (size_t i = 0; i < n; i += 2) {
@ -379,8 +379,8 @@ void ExportCursor::dump (triagens::basics::StringBuffer& buffer) {
}
// finally adjust the length of the patched JSON so the NULL fields at
// the end will not be dumped
obj->_value._objects._length = j;
// the end will not be dumped
TRI_SetLengthVector(&obj->_value._objects, j);
}
else {
// no restrictions

View File

@ -4266,7 +4266,7 @@ static void JS_DatafileScanVocbaseCol (const v8::FunctionCallbackInfo<v8::Value>
v8::Handle<v8::Array> entries = v8::Array::New(isolate);
result->Set(TRI_V8_ASCII_STRING("entries"), entries);
for (size_t i = 0; i < scan._entries._length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(&scan._entries); ++i) {
TRI_df_scan_entry_t* entry = (TRI_df_scan_entry_t*) TRI_AtVector(&scan._entries, i);
v8::Handle<v8::Object> o = v8::Object::New(isolate);

View File

@ -398,7 +398,7 @@ static TRI_index_operator_t* SetupConditionsSkiplist (v8::Isolate* isolate,
nullptr,
clonedParams,
shaper,
clonedParams->_value._objects._length);
TRI_LengthVector(&clonedParams->_value._objects));
numEq = 0;
}
@ -410,7 +410,7 @@ static TRI_index_operator_t* SetupConditionsSkiplist (v8::Isolate* isolate,
nullptr,
cloned,
shaper,
cloned->_value._objects._length);
TRI_LengthVector(&cloned->_value._objects));
if (current == nullptr) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, cloned);
@ -458,7 +458,7 @@ static TRI_index_operator_t* SetupConditionsSkiplist (v8::Isolate* isolate,
nullptr,
clonedParams,
shaper,
clonedParams->_value._objects._length);
TRI_LengthVector(&clonedParams->_value._objects));
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, parameters);
@ -512,14 +512,14 @@ static TRI_index_operator_t* SetupExampleSkiplist (v8::Isolate* isolate,
TRI_PushBack3ArrayJson(TRI_UNKNOWN_MEM_ZONE, parameters, json);
}
if (parameters->_value._objects._length > 0) {
if (TRI_LengthArrayJson(parameters) > 0) {
// example means equality comparisons only
return TRI_CreateIndexOperator(TRI_EQ_INDEX_OPERATOR,
nullptr,
nullptr,
parameters,
shaper,
parameters->_value._objects._length);
TRI_LengthArrayJson(parameters));
}
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, parameters);
@ -556,7 +556,7 @@ static int SetupSearchValue (TRI_vector_t const* paths,
v8::Isolate* isolate = args.GetIsolate();
// extract attribute paths
size_t n = paths->_length;
size_t n = TRI_LengthVector(paths);
// setup storage
result._length = n;

View File

@ -520,7 +520,7 @@ class KeySpace {
TRI_json_t* item = static_cast<TRI_json_t*>(TRI_AtVector(&current->_value._objects, n - 1));
// hack: decrease the vector size
--current->_value._objects._length;
TRI_SetLengthVector(&current->_value._objects, TRI_LengthVector(&current->_value._objects) - 1);
v8::Handle<v8::Value> result = TRI_ObjectJson(isolate, item);
TRI_DestroyJson(TRI_UNKNOWN_MEM_ZONE, item);
@ -572,7 +572,7 @@ class KeySpace {
auto element = new KeySpaceElement(keyTo.c_str(), keyTo.size(), list);
TRI_InsertKeyAssociativePointer(&_hash, element->key, element, false);
// hack: decrease the vector size
--current->_value._objects._length;
TRI_SetLengthVector(&current->_value._objects, TRI_LengthVector(&current->_value._objects) - 1);
TRI_V8_RETURN(TRI_ObjectJson(isolate, sourceItem));
}
@ -589,7 +589,7 @@ class KeySpace {
TRI_PushBack2ArrayJson(dest->json, sourceItem);
// hack: decrease the vector size
--current->_value._objects._length;
TRI_SetLengthVector(&current->_value._objects, TRI_LengthVector(&current->_value._objects) - 1);
TRI_V8_RETURN(TRI_ObjectJson(isolate, sourceItem));
}
@ -653,7 +653,8 @@ class KeySpace {
TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL);
}
size_t const n = found->json->_value._objects._length;
size_t const n = TRI_LengthArrayJson(found->json);
if (index < 0) {
index = static_cast<int64_t>(n) + index;
}
@ -689,7 +690,8 @@ class KeySpace {
return false;
}
size_t const n = found->json->_value._objects._length;
size_t const n = TRI_LengthArrayJson(found->json);
if (index < 0) {
// TODO: change error code
return false;

View File

@ -574,8 +574,9 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo<v8::Value>& args,
// note: "fields" is not mandatory for all index types
// copy all field names (attributes)
for (size_t i = 0; i < value->_value._objects._length; ++i) {
TRI_json_t const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&value->_value._objects, i));
size_t const n = TRI_LengthArrayJson(value);
for (size_t i = 0; i < n; ++i) {
auto v = static_cast<TRI_json_t const*>(TRI_AtVector(&value->_value._objects, i));
if (TRI_IsStringJson(v)) {
TRI_PushBackVectorPointer(&attributes, v->_value._string.data);
@ -583,7 +584,7 @@ static void EnsureIndexLocal (const v8::FunctionCallbackInfo<v8::Value>& args,
}
// check if copying was successful
if (value->_value._objects._length != TRI_LengthVectorPointer(&attributes)) {
if (n != TRI_LengthVectorPointer(&attributes)) {
TRI_V8_THROW_EXCEPTION_MEMORY();
}
}
@ -877,7 +878,7 @@ static void EnsureIndex (const v8::FunctionCallbackInfo<v8::Value>& args,
if (TRI_IsArrayJson(flds) && c->numberOfShards() > 1) {
vector<string> const& shardKeys = c->shardKeys();
size_t const n = flds->_value._objects._length;
size_t const n = TRI_LengthArrayJson(flds);
if (shardKeys.size() != n) {
res = TRI_ERROR_CLUSTER_UNSUPPORTED;
@ -1396,8 +1397,9 @@ static void GetIndexesCoordinator (const v8::FunctionCallbackInfo<v8::Value>& ar
TRI_json_t const* json = (*c).getIndexes();
if (TRI_IsArrayJson(json)) {
uint32_t j = 0;
size_t const n = TRI_LengthArrayJson(json);
for (size_t i = 0; i < json->_value._objects._length; ++i) {
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(json, i);
if (v != nullptr) {

View File

@ -458,7 +458,8 @@ bool TRI_PopulateAuthInfo (TRI_vocbase_t* vocbase,
TRI_WriteLockReadWriteLock(&vocbase->_authInfoLock);
ClearAuthInfo(vocbase);
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthArrayJson(json);
for (size_t i = 0; i < n; ++i) {
TRI_vocbase_auth_t* auth = AuthFromJson(TRI_LookupArrayJson(json, i));

View File

@ -807,7 +807,7 @@ static void FillParametersFromJson (TRI_col_info_t* parameters,
parameters->_initialCount = -1;
// convert json
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));

View File

@ -755,7 +755,8 @@ static compaction_initial_context_t InitCompaction (TRI_document_collection_t* d
sizeof(TRI_df_footer_marker_t) +
256; // allow for some overhead
size_t const n = compactions->_length;
size_t const n = TRI_LengthVector(compactions);
for (size_t i = 0; i < n; ++i) {
compaction_info_t* compaction = static_cast<compaction_info_t*>(TRI_AtVector(compactions, i));
TRI_datafile_t* df = compaction->_datafile;
@ -789,7 +790,7 @@ static void CompactifyDatafiles (TRI_document_collection_t* document,
compaction_context_t context;
size_t i, j, n;
n = compactions->_length;
n = TRI_LengthVector(compactions);
TRI_ASSERT(n > 0);
// create a fake transaction
@ -1122,14 +1123,14 @@ static bool CompactifyDocumentCollection (TRI_document_collection_t* document) {
// can now continue without the lock
TRI_READ_UNLOCK_DATAFILES_DOC_COLLECTION(document);
if (vector._length == 0) {
if (TRI_LengthVector(&vector) == 0) {
// cleanup local variables
TRI_DestroyVector(&vector);
return false;
}
// handle datafiles with dead objects
TRI_ASSERT(vector._length >= 1);
TRI_ASSERT(TRI_LengthVector(&vector) >= 1);
CompactifyDatafiles(document, &vector);
@ -1185,7 +1186,7 @@ static bool CheckAndLockCompaction (TRI_vocbase_t* vocbase) {
double now = TRI_microtime();
// check if we have a still-valid compaction blocker
size_t const n = vocbase->_compactionBlockers._data._length;
size_t const n = TRI_LengthVector(&vocbase->_compactionBlockers._data);
for (size_t i = 0; i < n; ++i) {
compaction_blocker_t* blocker = static_cast<compaction_blocker_t*>(TRI_AtVector(&vocbase->_compactionBlockers._data, i));
@ -1237,7 +1238,7 @@ bool TRI_CleanupCompactorVocBase (TRI_vocbase_t* vocbase) {
// we are now holding the write lock
double now = TRI_microtime();
size_t n = vocbase->_compactionBlockers._data._length;
size_t n = TRI_LengthVector(&vocbase->_compactionBlockers._data);
size_t i = 0;
while (i < n) {
compaction_blocker_t* blocker = static_cast<compaction_blocker_t*>(TRI_AtVector(&vocbase->_compactionBlockers._data, i));
@ -1301,7 +1302,7 @@ int TRI_TouchBlockerCompactorVocBase (TRI_vocbase_t* vocbase,
LockCompaction(vocbase);
size_t const n = vocbase->_compactionBlockers._data._length;
size_t const n = TRI_LengthVector(&vocbase->_compactionBlockers._data);
for (size_t i = 0; i < n; ++i) {
compaction_blocker_t* blocker = static_cast<compaction_blocker_t*>(TRI_AtVector(&vocbase->_compactionBlockers._data, i));
@ -1350,7 +1351,7 @@ int TRI_RemoveBlockerCompactorVocBase (TRI_vocbase_t* vocbase,
LockCompaction(vocbase);
size_t const n = vocbase->_compactionBlockers._data._length;
size_t const n = TRI_LengthVector(&vocbase->_compactionBlockers._data);
for (size_t i = 0; i < n; ++i) {
compaction_blocker_t* blocker = static_cast<compaction_blocker_t*>(TRI_AtVector(&vocbase->_compactionBlockers._data, i));

View File

@ -1751,6 +1751,9 @@ int TRI_SealDatafile (TRI_datafile_t* datafile) {
// create the footer
TRI_InitMarkerDatafile((char*) &footer, TRI_DF_MARKER_FOOTER, sizeof(TRI_df_footer_marker_t));
// set a proper tick value
if (datafile->_tickMax == 0) {
datafile->_tickMax = TRI_NewTickServer();
}
footer.base._tick = datafile->_tickMax;
// reserve space and write footer to file

View File

@ -1400,7 +1400,7 @@ static int OpenIteratorAddOperation (open_iterator_state_t* state,
////////////////////////////////////////////////////////////////////////////////
static void OpenIteratorResetOperations (open_iterator_state_t* state) {
size_t n = state->_operations._length;
size_t n = TRI_LengthVector(&state->_operations);
if (n > OpenIteratorBufferSize * 2) {
// free some memory
@ -1426,7 +1426,7 @@ static int OpenIteratorStartTransaction (open_iterator_state_t* state,
state->_tid = tid;
state->_trxCollections = numCollections;
TRI_ASSERT(state->_operations._length == 0);
TRI_ASSERT(TRI_LengthVector(&state->_operations) == 0);
return TRI_ERROR_NO_ERROR;
}
@ -1461,7 +1461,7 @@ static int OpenIteratorAbortTransaction (open_iterator_state_t* state) {
int res = TRI_ERROR_NO_ERROR;
LOG_INFO("recovering transaction %llu", (unsigned long long) state->_tid);
size_t const n = state->_operations._length;
size_t const n = TRI_LengthVector(&state->_operations);
for (size_t i = 0; i < n; ++i) {
open_iterator_operation_t* operation = static_cast<open_iterator_operation_t*>(TRI_AtVector(&state->_operations, i));
@ -1497,11 +1497,9 @@ static int OpenIteratorCommitTransaction (open_iterator_state_t* state) {
int res = TRI_ERROR_NO_ERROR;
if (state->_trxCollections <= 1 || state->_trxPrepared) {
size_t i, n;
size_t const n = TRI_LengthVector(&state->_operations);
n = state->_operations._length;
for (i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
open_iterator_operation_t* operation = static_cast<open_iterator_operation_t*>(TRI_AtVector(&state->_operations, i));
int r = OpenIteratorApplyOperation(state, operation);
@ -3076,19 +3074,19 @@ static TRI_json_t* ExtractFields (TRI_json_t const* json,
TRI_json_t* fld = TRI_LookupObjectJson(json, "fields");
if (! TRI_IsArrayJson(fld)) {
LOG_ERROR("ignoring index %llu, 'fields' must be a list", (unsigned long long) iid);
LOG_ERROR("ignoring index %llu, 'fields' must be an array", (unsigned long long) iid);
TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
return nullptr;
}
*fieldCount = fld->_value._objects._length;
*fieldCount = TRI_LengthArrayJson(fld);
for (size_t j = 0; j < *fieldCount; ++j) {
TRI_json_t* sub = static_cast<TRI_json_t*>(TRI_AtVector(&fld->_value._objects, j));
if (! TRI_IsStringJson(sub)) {
LOG_ERROR("ignoring index %llu, 'fields' must be a list of attribute paths", (unsigned long long) iid);
LOG_ERROR("ignoring index %llu, 'fields' must be an array of attribute paths", (unsigned long long) iid);
TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
return nullptr;
@ -3215,7 +3213,7 @@ static TRI_index_t* LookupPathIndexDocumentCollection (TRI_document_collection_t
// of the number of attributes
// .........................................................................
if (paths->_length != indexPaths->_length) {
if (TRI_LengthVector(paths) != TRI_LengthVector(indexPaths)) {
continue;
}
@ -3227,12 +3225,14 @@ static TRI_index_t* LookupPathIndexDocumentCollection (TRI_document_collection_t
if (allowAnyAttributeOrder) {
// any permutation of attributes is allowed
for (size_t k = 0; k < paths->_length; ++k) {
size_t const n = TRI_LengthVector(paths);
for (size_t k = 0; k < n; ++k) {
TRI_shape_pid_t indexShape = *((TRI_shape_pid_t*) TRI_AtVector(indexPaths, k));
found = false;
for (size_t l = 0; l < paths->_length; ++l) {
for (size_t l = 0; l < n; ++l) {
TRI_shape_pid_t givenShape = *((TRI_shape_pid_t*) TRI_AtVector(paths, l));
if (indexShape == givenShape) {
@ -3247,8 +3247,10 @@ static TRI_index_t* LookupPathIndexDocumentCollection (TRI_document_collection_t
}
}
else {
// attributes need to present in a given order
for (size_t k = 0; k < paths->_length; ++k) {
// attributes need to bepresent in a given order
size_t const n = TRI_LengthVector(paths);
for (size_t k = 0; k < n; ++k) {
TRI_shape_pid_t indexShape = *((TRI_shape_pid_t*) TRI_AtVector(indexPaths, k));
TRI_shape_pid_t givenShape = *((TRI_shape_pid_t*) TRI_AtVector(paths, k));

View File

@ -458,8 +458,10 @@ TRI_json_t* TRI_JsonIndex (TRI_memory_zone_t* zone,
void TRI_CopyPathVector (TRI_vector_t* dst, TRI_vector_t* src) {
TRI_InitVector(dst, TRI_CORE_MEM_ZONE, sizeof(TRI_shape_pid_t));
for (size_t j = 0; j < src->_length; ++j) {
TRI_shape_pid_t shape = *((TRI_shape_pid_t*)(TRI_AtVector(src,j)));
size_t const n = TRI_LengthVector(src);
for (size_t j = 0; j < n; ++j) {
TRI_shape_pid_t shape = *((TRI_shape_pid_t*) (TRI_AtVector(src, j)));
TRI_PushBackVector(dst, &shape);
}
@ -1101,7 +1103,7 @@ static int FillLookupSLOperator (TRI_index_operator_t* slOperator,
case TRI_LE_INDEX_OPERATOR:
case TRI_LT_INDEX_OPERATOR: {
TRI_relation_index_operator_t* relationOperator = (TRI_relation_index_operator_t*) slOperator;
relationOperator->_numFields = relationOperator->_parameters->_value._objects._length;
relationOperator->_numFields = TRI_LengthVector(&relationOperator->_parameters->_value._objects);
relationOperator->_fields = static_cast<TRI_shaped_json_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_shaped_json_t) * relationOperator->_numFields, false));
if (relationOperator->_fields != nullptr) {
@ -1224,7 +1226,9 @@ static int SkiplistIndexHelper (TRI_skiplist_index_t const* skiplistIndex,
auto subObjects = SkiplistIndex_Subobjects(skiplistElement);
for (size_t j = 0; j < skiplistIndex->_paths._length; ++j) {
size_t const n = TRI_LengthVector(&skiplistIndex->_paths);
for (size_t j = 0; j < n; ++j) {
TRI_shape_pid_t shape = *((TRI_shape_pid_t*) TRI_AtVector(&skiplistIndex->_paths, j));
// ..........................................................................
@ -1366,14 +1370,16 @@ static TRI_json_t* JsonSkiplistIndex (TRI_index_t const* idx) {
// ..........................................................................
// Allocate sufficent memory for the field list
// ..........................................................................
size_t const n = TRI_LengthVector(&skiplistIndex->_paths);
char const** fieldList = static_cast<char const**>(TRI_Allocate(TRI_CORE_MEM_ZONE, (sizeof(char*) * skiplistIndex->_paths._length) , false));
char const** fieldList = static_cast<char const**>(TRI_Allocate(TRI_CORE_MEM_ZONE, (sizeof(char*) * n) , false));
// ..........................................................................
// Convert the attributes (field list of the skiplist index) into strings
// ..........................................................................
for (size_t j = 0; j < skiplistIndex->_paths._length; ++j) {
for (size_t j = 0; j < n; ++j) {
TRI_shape_pid_t shape = *((TRI_shape_pid_t*) TRI_AtVector(&skiplistIndex->_paths, j));
TRI_shape_path_t const* path = document->getShaper()->lookupAttributePathByPid(document->getShaper(), shape); // ONLY IN INDEX, PROTECTED by RUNTIME
@ -1392,7 +1398,7 @@ static TRI_json_t* JsonSkiplistIndex (TRI_index_t const* idx) {
TRI_json_t* json = TRI_JsonIndex(TRI_CORE_MEM_ZONE, idx);
TRI_json_t* fields = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);
for (size_t j = 0; j < skiplistIndex->_paths._length; ++j) {
for (size_t j = 0; j < n; ++j) {
TRI_PushBack3ArrayJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, fieldList[j], strlen(fieldList[j])));
}
TRI_Insert3ObjectJson(TRI_CORE_MEM_ZONE, json, "fields", fields);
@ -1487,7 +1493,7 @@ TRI_index_t* TRI_CreateSkiplistIndex (TRI_document_collection_t* document,
TRI_CopyDataFromVectorPointerVectorString(TRI_CORE_MEM_ZONE, &idx->_fields, fields);
skiplistIndex->_skiplistIndex = SkiplistIndex_new(document,
paths->_length,
TRI_LengthVector(paths),
unique);
if (skiplistIndex->_skiplistIndex == nullptr) {
@ -1884,20 +1890,24 @@ bool IndexComparator (TRI_json_t const* lhs,
if (TRI_IsArrayJson(value)) {
if (type == TRI_IDX_TYPE_HASH_INDEX) {
size_t const nv = TRI_LengthArrayJson(value);
// compare fields in arbitrary order
TRI_json_t const* r = TRI_LookupObjectJson(rhs, "fields");
if (! TRI_IsArrayJson(r) ||
value->_value._objects._length != r->_value._objects._length) {
nv != TRI_LengthArrayJson(r)) {
return false;
}
for (size_t i = 0; i < value->_value._objects._length; ++i) {
size_t const nr = TRI_LengthArrayJson(r);
for (size_t i = 0; i < nv; ++i) {
TRI_json_t const* v = TRI_LookupArrayJson(value, i);
bool found = false;
for (size_t j = 0; j < r->_value._objects._length; ++j) {
for (size_t j = 0; j < nr; ++j) {
if (TRI_CheckSameValueJson(v, TRI_LookupArrayJson(r, j))) {
found = true;
break;

View File

@ -1139,7 +1139,7 @@ static int DumpCollection (TRI_replication_dump_t* dump,
bufferFull = false;
ignoreMarkers = false;
n = datafiles._length;
n = TRI_LengthVector(&datafiles);
for (i = 0; i < n; ++i) {
df_entry_t* e = (df_entry_t*) TRI_AtVector(&datafiles, i);

View File

@ -688,7 +688,7 @@ namespace triagens {
TRI_json_t const* details = TRI_LookupObjectJson(json.get(), "details");
if (TRI_IsArrayJson(details)) {
size_t const n = details->_value._objects._length;
size_t const n = TRI_LengthArrayJson(details);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* detail = static_cast<TRI_json_t const*>(TRI_AtVector(&details->_value._objects, i));

View File

@ -741,7 +741,7 @@ static int RunDump (string& errorMsg) {
}
// iterate over collections
const size_t n = collections->_value._objects._length;
size_t const n = TRI_LengthArrayJson(collections);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* collection = (TRI_json_t const*) TRI_AtVector(&collections->_value._objects, i);
@ -1058,7 +1058,7 @@ static int RunClusterDump (string& errorMsg) {
}
// iterate over collections
const size_t n = collections->_value._objects._length;
size_t const n = TRI_LengthArrayJson(collections);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* collection = (TRI_json_t const*) TRI_AtVector(&collections->_value._objects, i);

View File

@ -647,15 +647,16 @@ static int ProcessInputDirectory (string& errorMsg) {
TRI_PushBack3ArrayJson(TRI_UNKNOWN_MEM_ZONE, collections, json);
}
}
size_t const n = TRI_LengthArrayJson(collections);
// sort collections according to type (documents before edges)
qsort(collections->_value._objects._buffer, collections->_value._objects._length, sizeof(TRI_json_t), &SortCollections);
qsort(collections->_value._objects._buffer, n, sizeof(TRI_json_t), &SortCollections);
StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE);
// step2: run the actual import
{
const size_t n = collections->_value._objects._length;
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* json = (TRI_json_t const*) TRI_AtVector(&collections->_value._objects, i);
TRI_json_t const* parameters = JsonHelper::getObjectElement(json, "parameters");

View File

@ -293,7 +293,7 @@ HttpHandler::status_t RestAdminLogHandler::execute () {
TRI_InitVector(&clean, TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_log_buffer_t));
for (size_t i = 0; i < logs->_length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(logs); ++i) {
TRI_log_buffer_t* buf = (TRI_log_buffer_t*) TRI_AtVector(logs, i);
if (search) {
@ -317,9 +317,9 @@ HttpHandler::status_t RestAdminLogHandler::execute () {
TRI_json_t* timestamp = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE);
TRI_json_t* text = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE);
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, &result, "totalAmount", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, (double) clean._length));
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, &result, "totalAmount", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, (double) TRI_LengthVector(&clean)));
size_t length = clean._length;
size_t length = TRI_LengthVector(&clean);
if (offset >= length) {
length = 0;

View File

@ -121,9 +121,11 @@ std::map<std::string, std::string> JsonHelper::stringObject (TRI_json_t const* j
std::map<std::string, std::string> result;
if (isObject(json)) {
for (size_t i = 0, n = json->_value._objects._length; i < n; i += 2) {
TRI_json_t const* k = (TRI_json_t const*) TRI_AtVector(&json->_value._objects, i);
TRI_json_t const* v = (TRI_json_t const*) TRI_AtVector(&json->_value._objects, i + 1);
size_t const n = TRI_LengthVectorJson(json);
for (size_t i = 0; i < n; i += 2) {
auto k = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
auto v = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i + 1));
if (isString(k) && isString(v)) {
std::string const key = std::string(k->_value._string.data, k->_value._string.length - 1);
@ -150,6 +152,7 @@ TRI_json_t* JsonHelper::stringArray (TRI_memory_zone_t* zone,
for (size_t i = 0, n = values.size(); i < n; ++i) {
TRI_json_t* v = TRI_CreateStringCopyJson(zone, values[i].c_str(), values[i].size());
if (v != nullptr) {
TRI_PushBack3ArrayJson(zone, json, v);
}
@ -166,8 +169,10 @@ std::vector<std::string> JsonHelper::stringArray (TRI_json_t const* json) {
std::vector<std::string> result;
if (isArray(json)) {
for (size_t i = 0, n = json->_value._objects._length; i < n; ++i) {
TRI_json_t const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
size_t const n = TRI_LengthArrayJson(json);
for (size_t i = 0; i < n; ++i) {
auto v = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
if (isString(v)) {
result.emplace_back(std::string(v->_value._string.data, v->_value._string.length - 1));
@ -183,9 +188,7 @@ std::vector<std::string> JsonHelper::stringArray (TRI_json_t const* json) {
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* JsonHelper::fromString (std::string const& data) {
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data.c_str());
return json;
return TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data.c_str());
}
////////////////////////////////////////////////////////////////////////////////
@ -193,9 +196,7 @@ TRI_json_t* JsonHelper::fromString (std::string const& data) {
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* JsonHelper::fromString (char const* data) {
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data);
return json;
return TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data);
}
////////////////////////////////////////////////////////////////////////////////
@ -204,9 +205,7 @@ TRI_json_t* JsonHelper::fromString (char const* data) {
TRI_json_t* JsonHelper::fromString (char const* data,
size_t length) {
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data);
return json;
return TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, data);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -968,7 +968,7 @@ namespace triagens {
if (! TRI_IsArrayJson(_json)) {
throw JsonException("Json is no array");
}
return _json->_value._objects._length;
return TRI_LengthVector(&_json->_value._objects);
}
////////////////////////////////////////////////////////////////////////////////
@ -979,7 +979,7 @@ namespace triagens {
if (! TRI_IsObjectJson(_json)) {
throw JsonException("Json is no object");
}
return _json->_value._objects._length / 2;
return TRI_LengthVector(&_json->_value._objects) / 2;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -677,7 +677,7 @@ void ProgramOptions::setupSubDescription (ProgramOptionsDescription const& descr
bool ProgramOptions::extractValues (ProgramOptionsDescription const& description, TRI_program_options_t* options, set<string> seen) {
TRI_ASSERT(ProgramOptionsJson != nullptr);
for (size_t i = 0; i < options->_items._length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(&options->_items); ++i) {
TRI_PO_item_t * item = static_cast<TRI_PO_item_t*>(TRI_AtVector(&options->_items, i));
if (item->_used) {

View File

@ -47,8 +47,9 @@ static TRI_json_t* MergeRecursive (TRI_memory_zone_t* zone,
if (result == nullptr) {
return nullptr;
}
size_t const n = TRI_LengthVector(&rhs->_value._objects);
size_t const n = rhs->_value._objects._length;
for (size_t i = 0; i < n; i += 2) {
// enumerate all the replacement values
auto key = static_cast<TRI_json_t*>(TRI_AtVector(&rhs->_value._objects, i));
@ -141,15 +142,16 @@ static TRI_json_t* GetMergedKeyList (TRI_json_t const* lhs,
TRI_ASSERT(lhs->_type == TRI_JSON_OBJECT);
TRI_ASSERT(rhs->_type == TRI_JSON_OBJECT);
n = TRI_LengthVector(&lhs->_value._objects) + TRI_LengthVector(&rhs->_value._objects);
keys = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE,
lhs->_value._objects._length + rhs->_value._objects._length);
keys = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE, n);
if (keys == nullptr) {
return nullptr;
}
n = lhs->_value._objects._length;
n = TRI_LengthVector(&lhs->_value._objects);
for (i = 0 ; i < n; i += 2) {
auto key = reinterpret_cast<TRI_json_t*>(TRI_AtVector(&lhs->_value._objects, i));
@ -159,7 +161,7 @@ static TRI_json_t* GetMergedKeyList (TRI_json_t const* lhs,
}
n = rhs->_value._objects._length;
n = TRI_LengthVector(&rhs->_value._objects);
for (i = 0 ; i < n; i += 2) {
auto key = reinterpret_cast<TRI_json_t*>(TRI_AtVector(&rhs->_value._objects, i));
@ -266,8 +268,8 @@ int TRI_CompareValuesJson (TRI_json_t const* lhs,
}
case TRI_JSON_ARRAY: {
size_t const nl = lhs->_value._objects._length;
size_t const nr = rhs->_value._objects._length;
size_t const nl = TRI_LengthVector(&lhs->_value._objects);
size_t const nr = TRI_LengthVector(&rhs->_value._objects);
size_t n;
if (nl > nr) {
@ -298,7 +300,7 @@ int TRI_CompareValuesJson (TRI_json_t const* lhs,
TRI_json_t* keys = GetMergedKeyList(lhs, rhs);
if (keys != nullptr) {
size_t const n = keys->_value._objects._length;
size_t const n = TRI_LengthVector(&keys->_value._objects);
for (size_t i = 0; i < n; ++i) {
auto keyElement = static_cast<TRI_json_t const*>(TRI_AtVector(&keys->_value._objects, i));
@ -345,7 +347,7 @@ bool TRI_CheckInArrayJson (TRI_json_t const* search,
TRI_ASSERT(list->_type == TRI_JSON_ARRAY);
// iterate over list
size_t const n = list->_value._objects._length;
size_t const n = TRI_LengthVector(&list->_value._objects);
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* listValue = static_cast<TRI_json_t const*>(TRI_AtVector(&list->_value._objects, i));
@ -383,7 +385,7 @@ TRI_json_t* TRI_BetweenArrayJson (TRI_json_t const* list,
return nullptr;
}
n = list->_value._objects._length;
n = TRI_LengthVector(&list->_value._objects);
for (i = 0; i < n; ++i) {
auto p = reinterpret_cast<TRI_json_t*>(TRI_AtVector(&list->_value._objects, i));
@ -433,7 +435,7 @@ TRI_json_t* TRI_UniquifyArrayJson (TRI_json_t const* list) {
return nullptr;
}
n = list->_value._objects._length;
n = TRI_LengthVector(&list->_value._objects);
for (i = 0; i < n; ++i) {
auto p = reinterpret_cast<TRI_json_t*>(TRI_AtVector(&list->_value._objects, i));
@ -467,8 +469,8 @@ TRI_json_t* TRI_UnionizeListsJson (TRI_json_t const* list1,
TRI_ASSERT(list2);
TRI_ASSERT(list2->_type == TRI_JSON_ARRAY);
n1 = list1->_value._objects._length;
n2 = list2->_value._objects._length;
n1 = TRI_LengthVector(&list1->_value._objects);
n2 = TRI_LengthVector(&list2->_value._objects);
// special cases for empty lists
if (n1 == 0 && ! unique) {
@ -580,8 +582,8 @@ TRI_json_t* TRI_IntersectListsJson (TRI_json_t const* list1,
TRI_ASSERT(list2);
TRI_ASSERT(list2->_type == TRI_JSON_ARRAY);
n1 = list1->_value._objects._length;
n2 = list2->_value._objects._length;
n1 = TRI_LengthVector(&list1->_value._objects);
n2 = TRI_LengthVector(&list2->_value._objects);
// create result list
result = TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE, n1 > n2 ? n1 : n2);
@ -640,10 +642,12 @@ TRI_json_t* TRI_IntersectListsJson (TRI_json_t const* list1,
TRI_json_t* TRI_SortArrayJson (TRI_json_t* list) {
TRI_ASSERT(list != nullptr);
TRI_ASSERT(list->_type == TRI_JSON_ARRAY);
size_t const n = TRI_LengthVector(&list->_value._objects);
if (list->_value._objects._length > 1) {
if (n > 1) {
// only sort if more than one value in list
qsort(TRI_BeginVector(&list->_value._objects), list->_value._objects._length, sizeof(TRI_json_t), &CompareJson);
qsort(TRI_BeginVector(&list->_value._objects), n, sizeof(TRI_json_t), &CompareJson);
}
return list;
@ -655,7 +659,7 @@ TRI_json_t* TRI_SortArrayJson (TRI_json_t* list) {
bool TRI_HasDuplicateKeyJson (TRI_json_t const* object) {
if (object && object->_type == TRI_JSON_OBJECT) {
const size_t n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
const bool hasMultipleElements = (n > 2);
// if we don't have attributes, we do not need to check for duplicates
@ -795,7 +799,7 @@ static uint64_t HashJsonRecursive (uint64_t hash,
case TRI_JSON_OBJECT: {
hash = HashBlock(hash, "array", 5); // strlen("array")
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
uint64_t tmphash = hash;
for (size_t i = 0; i < n; i += 2) {
auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i));
@ -809,7 +813,7 @@ static uint64_t HashJsonRecursive (uint64_t hash,
case TRI_JSON_ARRAY: {
hash = HashBlock(hash, "list", 4); // strlen("list")
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; ++i) {
auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i));
hash = HashJsonRecursive(hash, subjson);
@ -906,7 +910,7 @@ static uint64_t FastHashJsonRecursive (uint64_t hash,
case TRI_JSON_OBJECT: {
hash = fasthash64(static_cast<const void*>("object"), 6, hash);
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
uint64_t tmphash = hash;
for (size_t i = 0; i < n; i += 2) {
auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i));
@ -920,7 +924,7 @@ static uint64_t FastHashJsonRecursive (uint64_t hash,
case TRI_JSON_ARRAY: {
hash = fasthash64(static_cast<const void*>("array"), 5, hash);
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; ++i) {
auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i));
hash = FastHashJsonRecursive(hash, subjson);

View File

@ -126,7 +126,7 @@ static int StringifyJson (TRI_memory_zone_t* zone,
}
}
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; i += 2) {
if (0 < i) {
@ -176,7 +176,7 @@ static int StringifyJson (TRI_memory_zone_t* zone,
}
}
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; ++i) {
if (0 < i) {
@ -529,10 +529,10 @@ void TRI_DestroyJson (TRI_memory_zone_t* zone, TRI_json_t* object) {
case TRI_JSON_OBJECT:
case TRI_JSON_ARRAY: {
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; ++i) {
TRI_json_t* v = static_cast<TRI_json_t*>(TRI_AddressVector(&object->_value._objects, i));
auto v = static_cast<TRI_json_t*>(TRI_AddressVector(&object->_value._objects, i));
TRI_DestroyJson(zone, v);
}
@ -586,8 +586,18 @@ char const* TRI_GetTypeStringJson (TRI_json_t const* object) {
////////////////////////////////////////////////////////////////////////////////
size_t TRI_LengthArrayJson (TRI_json_t const* json) {
TRI_ASSERT(json != nullptr && json->_type==TRI_JSON_ARRAY);
return json->_value._objects._length;
TRI_ASSERT(json != nullptr && json->_type == TRI_JSON_ARRAY);
return TRI_LengthVector(&json->_value._objects);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief determines the length of the json's objects vector
////////////////////////////////////////////////////////////////////////////////
size_t TRI_LengthVectorJson (TRI_json_t const* json) {
TRI_ASSERT(json != nullptr &&
(json->_type == TRI_JSON_ARRAY || json->_type == TRI_JSON_OBJECT));
return TRI_LengthVector(&json->_value._objects);
}
////////////////////////////////////////////////////////////////////////////////
@ -689,7 +699,7 @@ int TRI_PushBack3ArrayJson (TRI_memory_zone_t* zone, TRI_json_t* array, TRI_json
TRI_json_t* TRI_LookupArrayJson (TRI_json_t const* array, size_t pos) {
TRI_ASSERT(array->_type == TRI_JSON_ARRAY);
size_t n = array->_value._objects._length;
size_t const n = TRI_LengthVector(&array->_value._objects);
if (pos >= n) {
// out of bounds
@ -801,7 +811,7 @@ TRI_json_t* TRI_LookupObjectJson (TRI_json_t const* object, char const* name) {
TRI_ASSERT(object->_type == TRI_JSON_OBJECT);
TRI_ASSERT(name != nullptr);
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
if (n >= 16) {
// if we have many attributes, try an algorithm that compares string length first
@ -849,7 +859,7 @@ bool TRI_DeleteObjectJson (TRI_memory_zone_t* zone, TRI_json_t* object, char con
TRI_ASSERT(object->_type == TRI_JSON_OBJECT);
TRI_ASSERT(name != nullptr);
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t* key = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i));
@ -892,7 +902,7 @@ bool TRI_ReplaceObjectJson (TRI_memory_zone_t* zone, TRI_json_t* object, char co
TRI_ASSERT(object->_type == TRI_JSON_OBJECT);
TRI_ASSERT(name != nullptr);
size_t const n = object->_value._objects._length;
size_t const n = TRI_LengthVector(&object->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t* key = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i));
@ -1091,7 +1101,7 @@ int TRI_CopyToJson (TRI_memory_zone_t* zone,
case TRI_JSON_OBJECT:
case TRI_JSON_ARRAY: {
size_t const n = src->_value._objects._length;
size_t const n = TRI_LengthVector(&src->_value._objects);
TRI_InitVector(&dst->_value._objects, zone, sizeof(TRI_json_t));
int res = TRI_ResizeVector(&dst->_value._objects, n);

View File

@ -210,6 +210,12 @@ char const* TRI_GetTypeStringJson (TRI_json_t const* object);
size_t TRI_LengthArrayJson (TRI_json_t const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief determines the length of the json's objects vector
////////////////////////////////////////////////////////////////////////////////
size_t TRI_LengthVectorJson (TRI_json_t const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief determines whether the JSON passed is of type object
////////////////////////////////////////////////////////////////////////////////

View File

@ -1373,7 +1373,7 @@ TRI_vector_t* TRI_BufferLogging (TRI_log_level_e level, uint64_t start, bool use
}
}
qsort(TRI_BeginVector(result), result->_length, sizeof(TRI_log_buffer_t), LidCompare);
qsort(TRI_BeginVector(result), TRI_LengthVector(result), sizeof(TRI_log_buffer_t), LidCompare);
return result;
}
@ -1383,7 +1383,7 @@ TRI_vector_t* TRI_BufferLogging (TRI_log_level_e level, uint64_t start, bool use
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeBufferLogging (TRI_vector_t* buffer) {
for (size_t i = 0; i < buffer->_length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(buffer); ++i) {
TRI_log_buffer_t* buf = static_cast<TRI_log_buffer_t*>(TRI_AtVector(buffer, i));
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, buf->_text);

View File

@ -55,10 +55,10 @@
void TRI_InitVector (TRI_vector_t* vector, TRI_memory_zone_t* zone, size_t elementSize) {
vector->_memoryZone = zone;
vector->_elementSize = elementSize;
vector->_buffer = nullptr;
vector->_length = 0;
vector->_capacity = 0;
vector->_lengthX = 0;
vector->_capacityX = 0;
vector->_elementSizeX = static_cast<uint32_t>(elementSize);
}
////////////////////////////////////////////////////////////////////////////////
@ -73,14 +73,14 @@ int TRI_InitVector2 (TRI_vector_t* vector,
TRI_InitVector(vector, zone, elementSize);
if (initialCapacity != 0) {
vector->_buffer = (char*) TRI_Allocate(vector->_memoryZone, (initialCapacity * vector->_elementSize), false);
vector->_buffer = static_cast<char*>(TRI_Allocate(vector->_memoryZone, (initialCapacity * static_cast<size_t>(vector->_elementSizeX)), false));
if (vector->_buffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
}
vector->_capacity = initialCapacity;
vector->_capacityX = static_cast<uint32_t>(initialCapacity);
return TRI_ERROR_NO_ERROR;
}
@ -114,28 +114,26 @@ void TRI_FreeVector (TRI_memory_zone_t* zone, TRI_vector_t* vector) {
int TRI_ReserveVector (TRI_vector_t* vector,
size_t extraCapacity) {
size_t oldLength = vector->_length;
size_t oldLength = static_cast<size_t>(vector->_lengthX);
size_t minLength = oldLength + extraCapacity;
size_t newSize;
char* newBuffer;
if (vector->_capacity >= minLength) {
if (static_cast<size_t>(vector->_capacityX) >= minLength) {
return TRI_ERROR_NO_ERROR;
}
newSize = vector->_capacity;
size_t newSize = static_cast<size_t>(vector->_capacityX);
while (newSize < minLength) {
newSize = (size_t) (1 + GROW_FACTOR * newSize);
}
newBuffer = static_cast<char*>(TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * vector->_elementSize));
auto newBuffer = static_cast<char*>(TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * static_cast<size_t>(vector->_elementSizeX)));
if (newBuffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
vector->_buffer = newBuffer;
vector->_capacity = newSize;
vector->_capacityX = static_cast<uint32_t>(newSize);
return TRI_ERROR_NO_ERROR;
}
@ -152,26 +150,26 @@ TRI_vector_t* TRI_CopyVector (TRI_memory_zone_t* zone,
return nullptr;
}
copy->_elementSize = vector->_elementSize;
copy->_elementSizeX = vector->_elementSizeX;
copy->_memoryZone = zone;
if (vector->_capacity == 0) {
copy->_buffer = nullptr;
copy->_length = 0;
copy->_capacity = 0;
if (vector->_capacityX == 0) {
copy->_buffer = nullptr;
copy->_lengthX = 0;
copy->_capacityX = 0;
}
else {
copy->_buffer = static_cast<char*>(TRI_Allocate(zone, vector->_length * vector->_elementSize, false));
copy->_buffer = static_cast<char*>(TRI_Allocate(zone, static_cast<size_t>(vector->_lengthX * vector->_elementSizeX), false));
if (copy->_buffer == nullptr) {
TRI_Free(zone, copy);
return nullptr;
}
copy->_capacity = vector->_length;
copy->_length = vector->_length;
copy->_capacityX = vector->_lengthX;
copy->_lengthX = vector->_lengthX;
memcpy(copy->_buffer, vector->_buffer, vector->_length * vector->_elementSize);
memcpy(copy->_buffer, vector->_buffer, static_cast<size_t>(vector->_lengthX * vector->_elementSizeX));
}
return copy;
@ -183,7 +181,7 @@ TRI_vector_t* TRI_CopyVector (TRI_memory_zone_t* zone,
int TRI_CopyDataVector (TRI_vector_t* dst,
TRI_vector_t const* source) {
if (dst->_elementSize != source->_elementSize) {
if (dst->_elementSizeX != source->_elementSizeX) {
return TRI_ERROR_INTERNAL;
}
@ -192,19 +190,19 @@ int TRI_CopyDataVector (TRI_vector_t* dst,
dst->_buffer = nullptr;
}
dst->_capacity = 0;
dst->_length = 0;
dst->_capacityX = 0;
dst->_lengthX = 0;
if (source->_length > 0) {
dst->_buffer = static_cast<char*>(TRI_Allocate(dst->_memoryZone, source->_length * source->_elementSize, false));
if (source->_lengthX > 0) {
dst->_buffer = static_cast<char*>(TRI_Allocate(dst->_memoryZone, static_cast<size_t>(source->_lengthX * source->_elementSizeX), false));
if (dst->_buffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
memcpy(dst->_buffer, source->_buffer, source->_length * source->_elementSize);
dst->_capacity = source->_length;
dst->_length = source->_length;
memcpy(dst->_buffer, source->_buffer, static_cast<size_t>(source->_lengthX * source->_elementSizeX));
dst->_capacityX = source->_lengthX;
dst->_lengthX = source->_lengthX;
}
return TRI_ERROR_NO_ERROR;
@ -215,15 +213,15 @@ int TRI_CopyDataVector (TRI_vector_t* dst,
////////////////////////////////////////////////////////////////////////////////
bool TRI_EmptyVector (TRI_vector_t const* vector) {
return vector->_length == 0;
return vector->_lengthX == 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the length of the vector
/// @brief adjusts the length of the vector
////////////////////////////////////////////////////////////////////////////////
size_t TRI_LengthVector (TRI_vector_t const* vector) {
return vector->_length;
void TRI_SetLengthVector (TRI_vector_t* vector, size_t n) {
vector->_lengthX = static_cast<uint32_t>(n);
}
////////////////////////////////////////////////////////////////////////////////
@ -231,7 +229,7 @@ size_t TRI_LengthVector (TRI_vector_t const* vector) {
////////////////////////////////////////////////////////////////////////////////
void TRI_ClearVector (TRI_vector_t* vector) {
vector->_length = 0;
vector->_lengthX = 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -240,25 +238,23 @@ void TRI_ClearVector (TRI_vector_t* vector) {
int TRI_ResizeVector (TRI_vector_t* vector,
size_t n) {
if (vector->_length == n) {
if (static_cast<size_t>(vector->_lengthX) == n) {
return TRI_ERROR_NO_ERROR;
}
if (vector->_capacity < n) {
char* newBuffer;
if (static_cast<size_t>(vector->_capacityX) < n) {
size_t newSize = n;
newBuffer = (char*) TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * vector->_elementSize);
auto newBuffer = static_cast<char*>(TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * static_cast<size_t>(vector->_elementSizeX)));
if (newBuffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
vector->_capacity = n;
vector->_capacityX = static_cast<uint32_t>(n);
vector->_buffer = newBuffer;
}
vector->_length = n;
vector->_lengthX = static_cast<uint32_t>(n);
return TRI_ERROR_NO_ERROR;
}
@ -267,23 +263,24 @@ int TRI_ResizeVector (TRI_vector_t* vector,
////////////////////////////////////////////////////////////////////////////////
int TRI_PushBackVector (TRI_vector_t* vector, void const* element) {
if (vector->_length == vector->_capacity) {
char* newBuffer;
size_t newSize = (size_t) (1 + (GROW_FACTOR * vector->_capacity));
size_t const elementSize = static_cast<size_t>(vector->_elementSizeX);
newBuffer = (char*) TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * vector->_elementSize);
if (vector->_lengthX == vector->_capacityX) {
size_t newSize = (size_t) (1 + (GROW_FACTOR * static_cast<size_t>(vector->_capacityX)));
auto newBuffer = static_cast<char*>(TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * elementSize));
if (newBuffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
vector->_capacity = newSize;
vector->_capacityX = static_cast<uint32_t>(newSize);
vector->_buffer = newBuffer;
}
memcpy(vector->_buffer + vector->_length * vector->_elementSize, element, vector->_elementSize);
memcpy(vector->_buffer + static_cast<size_t>(vector->_lengthX) * elementSize, element, elementSize);
vector->_length++;
vector->_lengthX++;
return TRI_ERROR_NO_ERROR;
}
@ -293,14 +290,16 @@ int TRI_PushBackVector (TRI_vector_t* vector, void const* element) {
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveVector (TRI_vector_t* vector, size_t n) {
if (n < vector->_length) {
if (n + 1 < vector->_length) {
memmove(vector->_buffer + n * vector->_elementSize,
vector->_buffer + (n + 1) * vector->_elementSize,
(vector->_length - n - 1) * vector->_elementSize);
if (n < static_cast<size_t>(vector->_lengthX)) {
if (n + 1 < static_cast<size_t>(vector->_lengthX)) {
size_t const elementSize = static_cast<size_t>(vector->_elementSizeX);
memmove(vector->_buffer + n * elementSize,
vector->_buffer + (n + 1) * elementSize,
(static_cast<size_t>(vector->_lengthX) - n - 1) * elementSize);
}
--vector->_length;
--vector->_lengthX;
}
}
@ -312,9 +311,9 @@ void TRI_RemoveVector (TRI_vector_t* vector, size_t n) {
////////////////////////////////////////////////////////////////////////////////
void TRI_ReturnVector (TRI_vector_t* vector) {
TRI_ASSERT(vector->_length > 0);
TRI_ASSERT(vector->_lengthX > 0);
vector->_length--;
vector->_lengthX--;
}
////////////////////////////////////////////////////////////////////////////////
@ -331,11 +330,11 @@ void* TRI_NextVector (TRI_vector_t* vector) {
return nullptr;
}
vector->_length++;
TRI_ASSERT(vector->_length <= vector->_capacity);
++vector->_lengthX;
TRI_ASSERT(vector->_lengthX <= vector->_capacityX);
TRI_ASSERT(vector->_buffer != nullptr);
return TRI_AtVector(vector, (vector->_length - 1));
return TRI_AtVector(vector, static_cast<size_t>(vector->_lengthX - 1));
}
////////////////////////////////////////////////////////////////////////////////
@ -343,11 +342,12 @@ void* TRI_NextVector (TRI_vector_t* vector) {
////////////////////////////////////////////////////////////////////////////////
void* TRI_AtVector (TRI_vector_t const* vector, size_t pos) {
if (vector->_buffer == nullptr || pos >= vector->_length) {
if (vector->_buffer == nullptr ||
pos >= static_cast<size_t>(vector->_lengthX)) {
return nullptr;
}
return static_cast<void*>(vector->_buffer + pos * vector->_elementSize);
return static_cast<void*>(vector->_buffer + pos * static_cast<size_t>(vector->_elementSizeX));
}
////////////////////////////////////////////////////////////////////////////////
@ -355,12 +355,15 @@ void* TRI_AtVector (TRI_vector_t const* vector, size_t pos) {
////////////////////////////////////////////////////////////////////////////////
int TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t n) {
size_t const elementSize = static_cast<size_t>(vector->_elementSizeX);
// ...........................................................................
// Check and see if we need to extend the vector
// ...........................................................................
if (vector->_length >= vector->_capacity || n >= vector->_capacity) {
size_t newSize = (size_t) (1 + (GROW_FACTOR * vector->_capacity));
if (vector->_lengthX >= vector->_capacityX ||
n >= static_cast<size_t>(vector->_capacityX)) {
size_t newSize = (size_t) (1 + (GROW_FACTOR * static_cast<size_t>(vector->_capacityX)));
if (n >= newSize) {
newSize = n + 1;
@ -368,34 +371,34 @@ int TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t n) {
TRI_ASSERT(newSize > n);
char* newBuffer = (char*) TRI_Allocate(vector->_memoryZone, newSize * vector->_elementSize, false);
auto newBuffer = static_cast<char*>(TRI_Allocate(vector->_memoryZone, newSize * elementSize, false));
if (newBuffer == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
vector->_capacity = newSize;
vector->_capacityX = static_cast<uint32_t>(newSize);
if (vector->_buffer != nullptr) {
memcpy(newBuffer, vector->_buffer, vector->_length * vector->_elementSize);
memcpy(newBuffer, vector->_buffer, static_cast<size_t>(vector->_lengthX) * elementSize);
TRI_Free(vector->_memoryZone, vector->_buffer);
}
vector->_buffer = newBuffer;
}
if (n < vector->_length) {
memmove(vector->_buffer + (vector->_elementSize * (n + 1)),
vector->_buffer + (vector->_elementSize * n),
vector->_elementSize * (vector->_length - n)
if (n < static_cast<size_t>(vector->_lengthX)) {
memmove(vector->_buffer + (elementSize * (n + 1)),
vector->_buffer + (elementSize * n),
elementSize * (static_cast<size_t>(vector->_lengthX) - n)
);
vector->_length += 1;
++vector->_lengthX;
}
else {
vector->_length = n + 1;
vector->_lengthX = static_cast<uint32_t>(n + 1);
}
memcpy(vector->_buffer + (vector->_elementSize * n), element, vector->_elementSize);
memcpy(vector->_buffer + (elementSize * n), element, elementSize);
return TRI_ERROR_NO_ERROR;
}
@ -405,8 +408,9 @@ int TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t n) {
////////////////////////////////////////////////////////////////////////////////
void TRI_SetVector (TRI_vector_t* vector, size_t pos, void const* element) {
if (pos < vector->_length) {
memcpy((void*)(vector->_buffer + pos * vector->_elementSize), element, vector->_elementSize);
if (pos < static_cast<size_t>(vector->_lengthX)) {
size_t const elementSize = static_cast<size_t>(vector->_elementSizeX);
memcpy((void*) (vector->_buffer + pos * elementSize), element, elementSize);
}
}
@ -423,7 +427,7 @@ void* TRI_BeginVector (TRI_vector_t const* vector) {
////////////////////////////////////////////////////////////////////////////////
void* TRI_EndVector (TRI_vector_t const* vector) {
return vector->_buffer + vector->_length * vector->_elementSize;
return vector->_buffer + static_cast<size_t>(vector->_lengthX * vector->_elementSizeX);
}
// -----------------------------------------------------------------------------

View File

@ -27,8 +27,8 @@
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_BASICS_C_VECTOR_H
#define ARANGODB_BASICS_C_VECTOR_H 1
#ifndef ARANGODB_BASICS_VECTOR_H
#define ARANGODB_BASICS_VECTOR_H 1
#include "Basics/Common.h"
@ -45,11 +45,11 @@
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_vector_s {
char* _buffer;
TRI_memory_zone_t* _memoryZone;
char * _buffer;
size_t _elementSize;
size_t _length;
size_t _capacity;
uint32_t _lengthX; // private. do not access from outside!
uint32_t _capacityX; // private. do not access from outside!
uint32_t _elementSizeX; // private. do not access from outside!
}
TRI_vector_t;
@ -61,7 +61,7 @@ TRI_vector_t;
/// @brief initialises a vector
////////////////////////////////////////////////////////////////////////////////
void TRI_InitVector (TRI_vector_t*, TRI_memory_zone_t*, size_t elementSize);
void TRI_InitVector (TRI_vector_t*, TRI_memory_zone_t*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises a vector, with user-definable settings
@ -69,8 +69,8 @@ void TRI_InitVector (TRI_vector_t*, TRI_memory_zone_t*, size_t elementSize);
int TRI_InitVector2 (TRI_vector_t*,
TRI_memory_zone_t*,
size_t elementSize,
size_t initialCapacity);
size_t,
size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a vector, but does not free the pointer
@ -82,12 +82,20 @@ void TRI_DestroyVector (TRI_vector_t*);
/// @brief destroys a vector and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeVector (TRI_memory_zone_t* zone, TRI_vector_t*);
void TRI_FreeVector (TRI_memory_zone_t*, TRI_vector_t*);
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief returns length of vector
////////////////////////////////////////////////////////////////////////////////
static inline size_t TRI_LengthVector (TRI_vector_t const* vector) {
return static_cast<size_t>(vector->_lengthX);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief ensures a vector has space for extraCapacity more items
////////////////////////////////////////////////////////////////////////////////
@ -116,10 +124,10 @@ int TRI_CopyDataVector (TRI_vector_t*,
bool TRI_EmptyVector (TRI_vector_t const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns length of vector
/// @brief adjusts the length of the vector
////////////////////////////////////////////////////////////////////////////////
size_t TRI_LengthVector (TRI_vector_t const*);
void TRI_SetLengthVector (TRI_vector_t*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief clears the vector
@ -137,13 +145,13 @@ int TRI_ResizeVector (TRI_vector_t*, size_t);
/// @brief adds and element at the end
////////////////////////////////////////////////////////////////////////////////
int TRI_PushBackVector (TRI_vector_t*, void const* element);
int TRI_PushBackVector (TRI_vector_t*, void const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an element
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveVector (TRI_vector_t*, size_t n);
void TRI_RemoveVector (TRI_vector_t*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns an element to the vector after borrowing it via
@ -166,7 +174,7 @@ void* TRI_NextVector (TRI_vector_t*);
////////////////////////////////////////////////////////////////////////////////
static inline void* TRI_AddressVector (TRI_vector_t const* vector, size_t pos) {
return static_cast<void*>(vector->_buffer + pos * vector->_elementSize);
return static_cast<void*>(vector->_buffer + pos * static_cast<size_t>(vector->_elementSizeX));
}
////////////////////////////////////////////////////////////////////////////////
@ -179,13 +187,13 @@ void* TRI_AtVector (TRI_vector_t const*, size_t);
/// @brief inserts an element at a given position
////////////////////////////////////////////////////////////////////////////////
int TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t position);
int TRI_InsertVector (TRI_vector_t*, void const* , size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief sets an element at a given position
////////////////////////////////////////////////////////////////////////////////
void TRI_SetVector (TRI_vector_t* vector, size_t, void const* element);
void TRI_SetVector (TRI_vector_t*, size_t, void const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the beginning

View File

@ -439,10 +439,11 @@ bool ApplicationEndpointServer::loadEndpoints () {
return false;
}
const size_t n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* e = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
TRI_json_t const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i + 1));
auto const* e = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
auto const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i + 1));
if (! TRI_IsStringJson(e) || ! TRI_IsArrayJson(v)) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
@ -452,16 +453,16 @@ bool ApplicationEndpointServer::loadEndpoints () {
const string endpoint = string(e->_value._string.data, e->_value._string.length - 1);
vector<string> dbNames;
for (size_t j = 0; j < v->_value._objects._length; ++j) {
TRI_json_t const* d = (TRI_json_t const*) TRI_AtVector(&v->_value._objects, j);
for (size_t j = 0; j < TRI_LengthVector(&v->_value._objects); ++j) {
auto d = static_cast<TRI_json_t const*>(TRI_AtVector(&v->_value._objects, j));
if (! TRI_IsStringJson(d)) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
return false;
}
const string dbName = string(d->_value._string.data, d->_value._string.length - 1);
dbNames.push_back(dbName);
std::string const dbName = string(d->_value._string.data, d->_value._string.length - 1);
dbNames.emplace_back(dbName);
}
endpoints[endpoint] = dbNames;

View File

@ -196,8 +196,8 @@ static void printUnrecognizedOption (TRI_program_options_t const* options,
std::multimap<int, std::string> distances;
for (size_t i = 0; i < options->_items._length; ++i) {
TRI_PO_item_t const* item = static_cast<TRI_PO_item_t const*>(TRI_AtVector(&options->_items, i));
for (size_t i = 0; i < TRI_LengthVector(&options->_items); ++i) {
auto item = static_cast<TRI_PO_item_t const*>(TRI_AtVector(&options->_items, i));
distances.emplace(TRI_Levenshtein(option, item->_desc->_name), item->_desc->_name);
}
@ -379,7 +379,7 @@ static void CreateDoubleOption (po_double_t * desc, const void * input, void * o
po = (TRI_program_options_t*) (output);
InitOptionStructure(&doubleOpt, desc->base._name, 1, 0, (int)(po->_longopts._length));
InitOptionStructure(&doubleOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -441,12 +441,7 @@ static void CreateFlagOption (po_flag_t * desc, const void * input, void * outpu
po = (TRI_program_options_t*) (output);
if (desc->_value == 0) {
InitOptionStructure(&flagOpt, desc->base._name, 0, 0, (int) po->_longopts._length);
}
else {
InitOptionStructure(&flagOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
}
InitOptionStructure(&flagOpt, desc->base._name, (desc->_value == 0 ? 0 : 1), 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -492,7 +487,7 @@ void CreateInt16Option (po_int16_t * desc, const void * input, void * output) {
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -533,7 +528,7 @@ void CreateInt32Option (po_int32_t * desc, const void * input, void * output) {
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -574,7 +569,7 @@ static void CreateInt64Option (po_int64_t * desc, const void * input, void * out
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -630,7 +625,7 @@ static void CreateStringOption (TRI_PO_string_t * desc, const void * input, void
po = (TRI_program_options_t *) output;
InitOptionStructure(&stringOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&stringOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -676,7 +671,7 @@ static void CreateUInt16Option (po_uint16_t * desc, const void * input, void * o
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -717,7 +712,7 @@ static void CreateUInt32Option (po_uint32_t * desc, const void * input, void * o
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -758,7 +753,7 @@ static void CreateUInt64Option (po_uint64_t * desc, const void * input, void * o
po = (TRI_program_options_t*) (output);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&intOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -795,7 +790,7 @@ static void CreateVectorStringOption (TRI_PO_vector_string_t * desc, const void
po = (TRI_program_options_t*) (output);
InitOptionStructure(&vectorOpt, desc->base._name, 1, 0, (int) po->_longopts._length);
InitOptionStructure(&vectorOpt, desc->base._name, 1, 0, (int) TRI_LengthVector(&po->_longopts));
memset(&item, 0, sizeof(item));
@ -901,7 +896,7 @@ static bool HandleOption (TRI_program_options_t * options,
full = TRI_Concatenate3String(section, ".", option);
}
for (size_t i = 0; i < options->_items._length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(&options->_items); ++i) {
TRI_PO_item_t* item = static_cast<TRI_PO_item_t*>(TRI_AtVector(&options->_items, i));
if (TRI_EqualString(full, item->_desc->_name)) {
@ -1527,7 +1522,7 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t* options,
// option with a missing value
TRI_AppendCharStringBuffer(&buffer, ':');
for (i = 0; i < options->_items._length; ++i) {
for (i = 0; i < TRI_LengthVector(&options->_items); ++i) {
item = static_cast<TRI_PO_item_t*>(TRI_AtVector(&options->_items, i));
if (item->_desc->_short != '\0') {
@ -1546,7 +1541,7 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t* options,
}
}
const char* shortOptions;
char const* shortOptions;
if (TRI_LengthStringBuffer(&buffer) == 0) {
shortOptions = "";
}
@ -1555,7 +1550,7 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t* options,
}
optind = 1;
maxIdx = (int) options->_items._length;
maxIdx = (int) TRI_LengthVector(&options->_items);
while (true) {
int c = getopt_long(argc, argv, shortOptions, (const struct option*) options->_longopts._buffer, &idx);
@ -1570,7 +1565,8 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t* options,
}
if (c < 256) {
for (i = 0; i < options->_items._length; ++i) {
size_t ni = TRI_LengthVector(&options->_items);
for (i = 0; i < ni; ++i) {
item = static_cast<TRI_PO_item_t*>(TRI_AtVector(&options->_items, i));
if (item->_desc->_short == c) {
@ -1578,7 +1574,7 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t* options,
}
}
if (i == options->_items._length) {
if (i == ni) {
if (optind - 1 > 0 && optind - 1 < argc) {
if ((char) c == ':') {
// missing argument
@ -1877,7 +1873,7 @@ bool TRI_ParseFileProgramOptions (TRI_program_options_t* options,
////////////////////////////////////////////////////////////////////////////////
bool TRI_HasOptionProgramOptions (TRI_program_options_t const* options, const char* name) {
for (size_t i = 0; i < options->_items._length; ++i) {
for (size_t i = 0; i < TRI_LengthVector(&options->_items); ++i) {
TRI_PO_item_t * item = static_cast<TRI_PO_item_t*>(TRI_AtVector(&options->_items, i));
if (item->_used && TRI_EqualString(name, item->_desc->_name)) {

View File

@ -475,7 +475,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
TRI_ASSERT(json->_type == TRI_JSON_ARRAY);
// check for special case "empty list"
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthArrayJson(json);
if (n == 0) {
dst->_type = TRI_SHAPE_LIST;
@ -723,10 +723,10 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
// sanity checks
TRI_ASSERT(json->_type == TRI_JSON_OBJECT);
TRI_ASSERT(json->_value._objects._length % 2 == 0);
TRI_ASSERT(TRI_LengthVector(&json->_value._objects) % 2 == 0);
// number of attributes
size_t n = json->_value._objects._length / 2;
size_t n = TRI_LengthVector(&json->_value._objects) / 2;
// convert into TRI_shape_value_t array
TRI_shape_value_t* values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->_memoryZone, n * sizeof(TRI_shape_value_t), true));
@ -793,7 +793,7 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
ok = false;
}
else {
TRI_json_t const* val = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, 2 * i + 1));
auto val = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, 2 * i + 1));
TRI_ASSERT(val != nullptr);
ok = FillShapeValueJson(shaper, p, val, level + 1, create);

View File

@ -1485,7 +1485,7 @@ static v8::Handle<v8::Value> ObjectJsonObject (v8::Isolate* isolate, TRI_json_t
v8::EscapableHandleScope scope(isolate);
v8::Handle<v8::Object> object = v8::Object::New(isolate);
size_t const n = json->_value._objects._length;
size_t const n = TRI_LengthVector(&json->_value._objects);
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* key = static_cast<TRI_json_t const*>(TRI_AddressVector(&json->_value._objects, i));
@ -1507,7 +1507,7 @@ static v8::Handle<v8::Value> ObjectJsonObject (v8::Isolate* isolate, TRI_json_t
static v8::Handle<v8::Value> ObjectJsonArray (v8::Isolate* isolate, TRI_json_t const* json) {
v8::EscapableHandleScope scope(isolate);
uint32_t const n = static_cast<uint32_t>(json->_value._objects._length);
uint32_t const n = static_cast<uint32_t>(TRI_LengthArrayJson(json));
v8::Handle<v8::Array> object = v8::Array::New(isolate, static_cast<int>(n));

View File

@ -608,7 +608,7 @@ static void JS_Download (const v8::FunctionCallbackInfo<v8::Value>& args) {
// endpoints should be an array
if (TRI_IsArrayJson(eps)) {
// it is. now iterate over the list and pick the first one
for (size_t i = 0; i < eps->_value._objects._length; ++i) {
for (size_t i = 0; i < TRI_LengthArrayJson(eps); ++i) {
auto ep = static_cast<TRI_json_t const*>(TRI_AtVector(&eps->_value._objects, i));
if (TRI_IsStringJson(ep)) {
@ -3926,39 +3926,6 @@ static void JS_IsIP (const v8::FunctionCallbackInfo<v8::Value>& args) {
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief adds attributes to object
////////////////////////////////////////////////////////////////////////////////
void TRI_AugmentObject (v8::Isolate* isolate, v8::Handle<v8::Value> value, TRI_json_t const* json) {
v8::HandleScope scope(isolate);
if (! value->IsObject()) {
return;
}
if (json->_type != TRI_JSON_OBJECT) {
return;
}
v8::Handle<v8::Object> object = value->ToObject();
size_t n = json->_value._objects._length;
for (size_t i = 0; i < n; i += 2) {
TRI_json_t* key = (TRI_json_t*) TRI_AtVector(&json->_value._objects, i);
if (! TRI_IsStringJson(key)) {
continue;
}
TRI_json_t* j = (TRI_json_t*) TRI_AtVector(&json->_value._objects, i + 1);
v8::Handle<v8::Value> val = TRI_ObjectJson(isolate, j);
object->Set(TRI_V8_STRING(key->_value._string.data), val);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief reports an exception
////////////////////////////////////////////////////////////////////////////////

View File

@ -132,12 +132,6 @@ static T* TRI_UnwrapClass (v8::Handle<v8::Object> obj, int32_t type) {
return static_cast<T*>(v8::Handle<v8::External>::Cast(obj->GetInternalField(SLOT_CLASS))->Value());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief adds attributes to array
////////////////////////////////////////////////////////////////////////////////
void TRI_AugmentObject (v8::Handle<v8::Value>, TRI_json_t const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief reports an exception
////////////////////////////////////////////////////////////////////////////////