mirror of https://gitee.com/bigwinds/arangodb
cleanup
This commit is contained in:
parent
e250a31b0c
commit
1e0dae153c
|
@ -97,10 +97,11 @@ TRI_shape_t const BasicShapes::_shapeList = {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief hashs the attribute path identifier
|
/// @brief hashes the attribute path identifier
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static uint64_t HashPidKeyAttributePath (TRI_associative_synced_t* array, void const* key) {
|
static uint64_t HashPidKeyAttributePath (TRI_associative_synced_t* array,
|
||||||
|
void const* key) {
|
||||||
return TRI_FnvHashPointer(key, sizeof(TRI_shape_pid_t));
|
return TRI_FnvHashPointer(key, sizeof(TRI_shape_pid_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +109,9 @@ static uint64_t HashPidKeyAttributePath (TRI_associative_synced_t* array, void c
|
||||||
/// @brief hashs the attribute path
|
/// @brief hashs the attribute path
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static uint64_t HashPidElementAttributePath (TRI_associative_synced_t* array, void const* element) {
|
static uint64_t HashPidElementAttributePath (TRI_associative_synced_t* array,
|
||||||
TRI_shape_path_t const* e;
|
void const* element) {
|
||||||
|
auto e = static_cast<TRI_shape_path_t const*>(element);
|
||||||
e = (TRI_shape_path_t const*) element;
|
|
||||||
|
|
||||||
return TRI_FnvHashPointer(&e->_pid, sizeof(TRI_shape_pid_t));
|
return TRI_FnvHashPointer(&e->_pid, sizeof(TRI_shape_pid_t));
|
||||||
}
|
}
|
||||||
|
@ -120,12 +120,11 @@ static uint64_t HashPidElementAttributePath (TRI_associative_synced_t* array, vo
|
||||||
/// @brief compares an attribute path identifier and an attribute path
|
/// @brief compares an attribute path identifier and an attribute path
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool EqualPidKeyAttributePath (TRI_associative_synced_t* array, void const* key, void const* element) {
|
static bool EqualPidKeyAttributePath (TRI_associative_synced_t* array,
|
||||||
TRI_shape_pid_t const* k;
|
void const* key,
|
||||||
TRI_shape_path_t const* e;
|
void const* element) {
|
||||||
|
auto k = static_cast<TRI_shape_pid_t const*>(key);
|
||||||
k = (TRI_shape_pid_t const*) key;
|
auto e = static_cast<TRI_shape_path_t const*>(element);
|
||||||
e = (TRI_shape_path_t const*) element;
|
|
||||||
|
|
||||||
return *k == e->_pid;
|
return *k == e->_pid;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,8 @@ static bool EqualPidKeyAttributePath (TRI_associative_synced_t* array, void cons
|
||||||
/// @brief looks up an attribute path by identifier
|
/// @brief looks up an attribute path by identifier
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static TRI_shape_path_t const* LookupAttributePathByPid (TRI_shaper_t* shaper, TRI_shape_pid_t pid) {
|
static TRI_shape_path_t const* LookupAttributePathByPid (TRI_shaper_t* shaper,
|
||||||
|
TRI_shape_pid_t pid) {
|
||||||
return static_cast<TRI_shape_path_t const*>(TRI_LookupByKeyAssociativeSynced(&shaper->_attributePathsByPid, &pid));
|
return static_cast<TRI_shape_path_t const*>(TRI_LookupByKeyAssociativeSynced(&shaper->_attributePathsByPid, &pid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,24 +142,19 @@ static TRI_shape_path_t const* LookupAttributePathByPid (TRI_shaper_t* shaper, T
|
||||||
/// @brief hashs the attribute path name
|
/// @brief hashs the attribute path name
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static uint64_t HashNameKeyAttributePath (TRI_associative_synced_t* array, void const* key) {
|
static uint64_t HashNameKeyAttributePath (TRI_associative_synced_t* array,
|
||||||
char const* k;
|
void const* key) {
|
||||||
|
return TRI_FnvHashString(static_cast<char const*>(key));
|
||||||
k = (char const*) key;
|
|
||||||
|
|
||||||
return TRI_FnvHashString(k);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief hashs the attribute path
|
/// @brief hashs the attribute path
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static uint64_t HashNameElementAttributePath (TRI_associative_synced_t* array, void const* element) {
|
static uint64_t HashNameElementAttributePath (TRI_associative_synced_t* array,
|
||||||
char const* e;
|
void const* element) {
|
||||||
TRI_shape_path_t const* ee;
|
char const* e = static_cast<char const*>(element);
|
||||||
|
TRI_shape_path_t const* ee = static_cast<TRI_shape_path_t const*>(element);
|
||||||
e = (char const*) element;
|
|
||||||
ee = (TRI_shape_path_t const*) element;
|
|
||||||
|
|
||||||
return TRI_FnvHashPointer(e + sizeof(TRI_shape_path_t) + ee->_aidLength * sizeof(TRI_shape_aid_t),
|
return TRI_FnvHashPointer(e + sizeof(TRI_shape_path_t) + ee->_aidLength * sizeof(TRI_shape_aid_t),
|
||||||
ee->_nameLength - 1);
|
ee->_nameLength - 1);
|
||||||
|
@ -169,14 +164,12 @@ static uint64_t HashNameElementAttributePath (TRI_associative_synced_t* array, v
|
||||||
/// @brief compares an attribute name and an attribute
|
/// @brief compares an attribute name and an attribute
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool EqualNameKeyAttributePath (TRI_associative_synced_t* array, void const* key, void const* element) {
|
static bool EqualNameKeyAttributePath (TRI_associative_synced_t* array,
|
||||||
char const* k;
|
void const* key,
|
||||||
char const* e;
|
void const* element) {
|
||||||
TRI_shape_path_t const* ee;
|
char const* k = static_cast<char const*>(key);
|
||||||
|
char const* e = static_cast<char const*>(element);
|
||||||
k = (char const*) key;
|
TRI_shape_path_t const* ee = static_cast<TRI_shape_path_t const*>(element);
|
||||||
e = (char const*) element;
|
|
||||||
ee = (TRI_shape_path_t const*) element;
|
|
||||||
|
|
||||||
return TRI_EqualString(k,e + sizeof(TRI_shape_path_t) + ee->_aidLength * sizeof(TRI_shape_aid_t));
|
return TRI_EqualString(k,e + sizeof(TRI_shape_path_t) + ee->_aidLength * sizeof(TRI_shape_aid_t));
|
||||||
}
|
}
|
||||||
|
@ -188,27 +181,21 @@ static bool EqualNameKeyAttributePath (TRI_associative_synced_t* array, void con
|
||||||
static TRI_shape_path_t const* FindShapePathByName (TRI_shaper_t* shaper,
|
static TRI_shape_path_t const* FindShapePathByName (TRI_shaper_t* shaper,
|
||||||
char const* name,
|
char const* name,
|
||||||
bool create) {
|
bool create) {
|
||||||
TRI_shape_aid_t* aids;
|
|
||||||
TRI_shape_path_t* result;
|
|
||||||
size_t count;
|
|
||||||
size_t len;
|
|
||||||
size_t total;
|
|
||||||
char* buffer;
|
char* buffer;
|
||||||
char* end;
|
char* end;
|
||||||
char* prev;
|
char* prev;
|
||||||
char* ptr;
|
char* ptr;
|
||||||
void const* p;
|
|
||||||
|
|
||||||
TRI_ASSERT(name != nullptr);
|
TRI_ASSERT(name != nullptr);
|
||||||
|
|
||||||
p = TRI_LookupByKeyAssociativeSynced(&shaper->_attributePathsByName, name);
|
void const* p = TRI_LookupByKeyAssociativeSynced(&shaper->_attributePathsByName, name);
|
||||||
|
|
||||||
if (p != nullptr) {
|
if (p != nullptr) {
|
||||||
return (TRI_shape_path_t const*) p;
|
return (TRI_shape_path_t const*) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a attribute path
|
// create an attribute path
|
||||||
len = strlen(name);
|
size_t len = strlen(name);
|
||||||
|
|
||||||
// lock the index and check that the element is still missing
|
// lock the index and check that the element is still missing
|
||||||
TRI_LockMutex(&shaper->_attributePathLock);
|
TRI_LockMutex(&shaper->_attributePathLock);
|
||||||
|
@ -222,8 +209,8 @@ static TRI_shape_path_t const* FindShapePathByName (TRI_shaper_t* shaper,
|
||||||
}
|
}
|
||||||
|
|
||||||
// split path into attribute pieces
|
// split path into attribute pieces
|
||||||
count = 0;
|
size_t count = 0;
|
||||||
aids = static_cast<TRI_shape_aid_t*>(TRI_Allocate(shaper->_memoryZone, len * sizeof(TRI_shape_aid_t), false));
|
TRI_shape_aid_t* aids = static_cast<TRI_shape_aid_t*>(TRI_Allocate(shaper->_memoryZone, len * sizeof(TRI_shape_aid_t), false));
|
||||||
|
|
||||||
if (aids == nullptr) {
|
if (aids == nullptr) {
|
||||||
TRI_UnlockMutex(&shaper->_attributePathLock);
|
TRI_UnlockMutex(&shaper->_attributePathLock);
|
||||||
|
@ -272,8 +259,8 @@ static TRI_shape_path_t const* FindShapePathByName (TRI_shaper_t* shaper,
|
||||||
TRI_FreeString(shaper->_memoryZone, buffer);
|
TRI_FreeString(shaper->_memoryZone, buffer);
|
||||||
|
|
||||||
// create element
|
// create element
|
||||||
total = sizeof(TRI_shape_path_t) + (len + 1) + (count * sizeof(TRI_shape_aid_t));
|
size_t total = sizeof(TRI_shape_path_t) + (len + 1) + (count * sizeof(TRI_shape_aid_t));
|
||||||
result = static_cast<TRI_shape_path_t*>(TRI_Allocate(shaper->_memoryZone, total, false));
|
TRI_shape_path_t* result = static_cast<TRI_shape_path_t*>(TRI_Allocate(shaper->_memoryZone, total, false));
|
||||||
|
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
TRI_UnlockMutex(&shaper->_attributePathLock);
|
TRI_UnlockMutex(&shaper->_attributePathLock);
|
||||||
|
@ -416,7 +403,6 @@ void TRI_DestroyShaper (TRI_shaper_t* shaper) {
|
||||||
|
|
||||||
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByName);
|
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByName);
|
||||||
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByPid);
|
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByPid);
|
||||||
|
|
||||||
TRI_DestroyMutex(&shaper->_attributePathLock);
|
TRI_DestroyMutex(&shaper->_attributePathLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,11 +209,8 @@ void TRI_PrintShape (TRI_shaper_t* shaper, TRI_shape_t const* shape, int indent)
|
||||||
|
|
||||||
static void PrintShapeValues (TRI_shape_value_t* values,
|
static void PrintShapeValues (TRI_shape_value_t* values,
|
||||||
size_t n) {
|
size_t n) {
|
||||||
TRI_shape_value_t* p;
|
TRI_shape_value_t* p = values;
|
||||||
TRI_shape_value_t* e;
|
TRI_shape_value_t* e = values + n;
|
||||||
|
|
||||||
p = values;
|
|
||||||
e = values + n;
|
|
||||||
|
|
||||||
for (; p < e; ++p) {
|
for (; p < e; ++p) {
|
||||||
switch (p->_type) {
|
switch (p->_type) {
|
||||||
|
@ -310,7 +307,6 @@ static void PrintShapeValues (TRI_shape_value_t* values,
|
||||||
|
|
||||||
static int WeightShapeType (TRI_shape_type_t type) {
|
static int WeightShapeType (TRI_shape_type_t type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case TRI_SHAPE_NULL: return 100;
|
case TRI_SHAPE_NULL: return 100;
|
||||||
case TRI_SHAPE_BOOLEAN: return 200;
|
case TRI_SHAPE_BOOLEAN: return 200;
|
||||||
case TRI_SHAPE_NUMBER: return 300;
|
case TRI_SHAPE_NUMBER: return 300;
|
||||||
|
@ -335,20 +331,15 @@ static int WeightShapeType (TRI_shape_type_t type) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int SortShapeValuesFunc (void const* l, void const* r) {
|
static int SortShapeValuesFunc (void const* l, void const* r) {
|
||||||
TRI_shape_value_t const* left;
|
auto left = static_cast<TRI_shape_value_t const*>(l);
|
||||||
TRI_shape_value_t const* right;
|
auto right = static_cast<TRI_shape_value_t const*>(r);
|
||||||
int wl;
|
|
||||||
int wr;
|
|
||||||
|
|
||||||
left = (TRI_shape_value_t const*) l;
|
|
||||||
right = (TRI_shape_value_t const*) r;
|
|
||||||
|
|
||||||
if (left->_fixedSized != right->_fixedSized) {
|
if (left->_fixedSized != right->_fixedSized) {
|
||||||
return (left->_fixedSized ? 0 : 1) - (right->_fixedSized ? 0 : 1);
|
return (left->_fixedSized ? 0 : 1) - (right->_fixedSized ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl = WeightShapeType(left->_type);
|
int wl = WeightShapeType(left->_type);
|
||||||
wr = WeightShapeType(right->_type);
|
int wr = WeightShapeType(right->_type);
|
||||||
|
|
||||||
if (wl != wr) {
|
if (wl != wr) {
|
||||||
return wl - wr;
|
return wl - wr;
|
||||||
|
@ -1073,9 +1064,7 @@ static TRI_json_t* JsonShapeDataBoolean (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
bool v;
|
bool v = (* (TRI_shape_boolean_t const*) data) != 0;
|
||||||
|
|
||||||
v = (* (TRI_shape_boolean_t const*) data) != 0;
|
|
||||||
|
|
||||||
return TRI_CreateBooleanJson(shaper->_memoryZone, v);
|
return TRI_CreateBooleanJson(shaper->_memoryZone, v);
|
||||||
}
|
}
|
||||||
|
@ -1088,9 +1077,7 @@ static TRI_json_t* JsonShapeDataNumber (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
TRI_shape_number_t v;
|
TRI_shape_number_t v = * (TRI_shape_number_t const*) (void const*) data;
|
||||||
|
|
||||||
v = * (TRI_shape_number_t const*) (void const*) data;
|
|
||||||
|
|
||||||
return TRI_CreateNumberJson(shaper->_memoryZone, v);
|
return TRI_CreateNumberJson(shaper->_memoryZone, v);
|
||||||
}
|
}
|
||||||
|
@ -1103,9 +1090,7 @@ static TRI_json_t* JsonShapeDataShortString (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
TRI_shape_length_short_string_t l;
|
TRI_shape_length_short_string_t l = * (TRI_shape_length_short_string_t const*) data;
|
||||||
|
|
||||||
l = * (TRI_shape_length_short_string_t const*) data;
|
|
||||||
data += sizeof(TRI_shape_length_short_string_t);
|
data += sizeof(TRI_shape_length_short_string_t);
|
||||||
|
|
||||||
return TRI_CreateStringCopyJson(shaper->_memoryZone, data, (size_t) (l - 1));
|
return TRI_CreateStringCopyJson(shaper->_memoryZone, data, (size_t) (l - 1));
|
||||||
|
@ -1119,9 +1104,7 @@ static TRI_json_t* JsonShapeDataLongString (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
TRI_shape_length_long_string_t l;
|
TRI_shape_length_long_string_t l = * (TRI_shape_length_long_string_t const*) data;
|
||||||
|
|
||||||
l = * (TRI_shape_length_long_string_t const*) data;
|
|
||||||
data += sizeof(TRI_shape_length_long_string_t);
|
data += sizeof(TRI_shape_length_long_string_t);
|
||||||
|
|
||||||
return TRI_CreateStringCopyJson(shaper->_memoryZone, data, l - 1);
|
return TRI_CreateStringCopyJson(shaper->_memoryZone, data, l - 1);
|
||||||
|
@ -1523,9 +1506,7 @@ static bool StringifyJsonShapeDataNull (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
int res;
|
int res = TRI_AppendString2StringBuffer(buffer, "null", 4);
|
||||||
|
|
||||||
res = TRI_AppendString2StringBuffer(buffer, "null", 4);
|
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1543,10 +1524,9 @@ static bool StringifyJsonShapeDataBoolean (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
bool v;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
v = (* (TRI_shape_boolean_t const*) data) != 0;
|
bool v = (* (TRI_shape_boolean_t const*) data) != 0;
|
||||||
|
|
||||||
if (v) {
|
if (v) {
|
||||||
res = TRI_AppendString2StringBuffer(buffer, "true", 4);
|
res = TRI_AppendString2StringBuffer(buffer, "true", 4);
|
||||||
|
@ -1571,10 +1551,9 @@ static bool StringifyJsonShapeDataNumber (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
TRI_shape_number_t v;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
v = * (TRI_shape_number_t const*) (void const*) data;
|
TRI_shape_number_t v = * (TRI_shape_number_t const*) (void const*) data;
|
||||||
// check for special values
|
// check for special values
|
||||||
|
|
||||||
// yes, this is intentional
|
// yes, this is intentional
|
||||||
|
@ -1610,11 +1589,9 @@ static bool StringifyJsonShapeDataShortString (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
int res;
|
|
||||||
|
|
||||||
data += sizeof(TRI_shape_length_short_string_t);
|
data += sizeof(TRI_shape_length_short_string_t);
|
||||||
|
|
||||||
res = TRI_AppendCharStringBuffer(buffer, '"');
|
int res = TRI_AppendCharStringBuffer(buffer, '"');
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1644,11 +1621,9 @@ static bool StringifyJsonShapeDataLongString (TRI_shaper_t* shaper,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
int res;
|
|
||||||
|
|
||||||
data += sizeof(TRI_shape_length_long_string_t);
|
data += sizeof(TRI_shape_length_long_string_t);
|
||||||
|
|
||||||
res = TRI_AppendCharStringBuffer(buffer, '"');
|
int res = TRI_AppendCharStringBuffer(buffer, '"');
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2237,7 +2212,7 @@ TRI_shaped_json_t* TRI_ShapedJsonJson (TRI_shaper_t* shaper,
|
||||||
bool create) {
|
bool create) {
|
||||||
TRI_shape_value_t dst;
|
TRI_shape_value_t dst;
|
||||||
|
|
||||||
dst._value = 0;
|
dst._value = nullptr;
|
||||||
bool ok = FillShapeValueJson(shaper, &dst, json, 0, create);
|
bool ok = FillShapeValueJson(shaper, &dst, json, 0, create);
|
||||||
|
|
||||||
if (! ok) {
|
if (! ok) {
|
||||||
|
@ -2254,7 +2229,9 @@ TRI_shaped_json_t* TRI_ShapedJsonJson (TRI_shaper_t* shaper,
|
||||||
TRI_shaped_json_t* shaped = static_cast<TRI_shaped_json_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_shaped_json_t), false));
|
TRI_shaped_json_t* shaped = static_cast<TRI_shaped_json_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_shaped_json_t), false));
|
||||||
|
|
||||||
if (shaped == nullptr) {
|
if (shaped == nullptr) {
|
||||||
TRI_Free(shaper->_memoryZone, dst._value);
|
if (dst._value != nullptr) {
|
||||||
|
TRI_Free(shaper->_memoryZone, dst._value);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2271,9 +2248,7 @@ TRI_shaped_json_t* TRI_ShapedJsonJson (TRI_shaper_t* shaper,
|
||||||
|
|
||||||
TRI_json_t* TRI_JsonShapedJson (TRI_shaper_t* shaper,
|
TRI_json_t* TRI_JsonShapedJson (TRI_shaper_t* shaper,
|
||||||
TRI_shaped_json_t const* shaped) {
|
TRI_shaped_json_t const* shaped) {
|
||||||
TRI_shape_t const* shape;
|
TRI_shape_t const* shape = shaper->lookupShapeId(shaper, shaped->_sid);
|
||||||
|
|
||||||
shape = shaper->lookupShapeId(shaper, shaped->_sid);
|
|
||||||
|
|
||||||
if (shape == nullptr) {
|
if (shape == nullptr) {
|
||||||
LOG_WARNING("cannot find shape #%u", (unsigned int) shaped->_sid);
|
LOG_WARNING("cannot find shape #%u", (unsigned int) shaped->_sid);
|
||||||
|
@ -2299,9 +2274,7 @@ bool TRI_StringifyArrayShapedJson (TRI_shaper_t* shaper,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prepend) {
|
if (prepend) {
|
||||||
TRI_array_shape_t const* s;
|
TRI_array_shape_t const* s = (TRI_array_shape_t const*) shape;
|
||||||
|
|
||||||
s = (TRI_array_shape_t const*) shape;
|
|
||||||
if (s->_fixedEntries + s->_variableEntries > 0) {
|
if (s->_fixedEntries + s->_variableEntries > 0) {
|
||||||
TRI_AppendCharStringBuffer(buffer, ',');
|
TRI_AppendCharStringBuffer(buffer, ',');
|
||||||
}
|
}
|
||||||
|
@ -2336,12 +2309,7 @@ bool TRI_StringifyAugmentedShapedJson (TRI_shaper_t* shaper,
|
||||||
struct TRI_string_buffer_s* buffer,
|
struct TRI_string_buffer_s* buffer,
|
||||||
TRI_shaped_json_t const* shaped,
|
TRI_shaped_json_t const* shaped,
|
||||||
TRI_json_t const* augment) {
|
TRI_json_t const* augment) {
|
||||||
TRI_shape_t const* shape;
|
TRI_shape_t const* shape = shaper->lookupShapeId(shaper, shaped->_sid);
|
||||||
bool ok;
|
|
||||||
uint64_t num;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
shape = shaper->lookupShapeId(shaper, shaped->_sid);
|
|
||||||
|
|
||||||
if (shape == nullptr) {
|
if (shape == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2351,13 +2319,14 @@ bool TRI_StringifyAugmentedShapedJson (TRI_shaper_t* shaper,
|
||||||
return StringifyJsonShapeData(shaper, buffer, shape, shaped->_data.data, shaped->_data.length);
|
return StringifyJsonShapeData(shaper, buffer, shape, shaped->_data.data, shaped->_data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = TRI_AppendCharStringBuffer(buffer, '{');
|
int res = TRI_AppendCharStringBuffer(buffer, '{');
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = StringifyJsonShapeDataArray(shaper, buffer, shape, shaped->_data.data, shaped->_data.length, false, &num);
|
uint64_t num;
|
||||||
|
bool ok = StringifyJsonShapeDataArray(shaper, buffer, shape, shaped->_data.data, shaped->_data.length, false, &num);
|
||||||
|
|
||||||
if (0 < num) {
|
if (0 < num) {
|
||||||
res = TRI_AppendCharStringBuffer(buffer, ',');
|
res = TRI_AppendCharStringBuffer(buffer, ',');
|
||||||
|
@ -2403,19 +2372,14 @@ bool TRI_AtListShapedJson (TRI_list_shape_t const* shape,
|
||||||
TRI_shaped_json_t const* json,
|
TRI_shaped_json_t const* json,
|
||||||
size_t position,
|
size_t position,
|
||||||
TRI_shaped_json_t* result) {
|
TRI_shaped_json_t* result) {
|
||||||
TRI_shape_length_list_t n;
|
char const* ptr = json->_data.data;
|
||||||
TRI_shape_sid_t* sids;
|
TRI_shape_length_list_t n = * (TRI_shape_length_list_t*) ptr;
|
||||||
TRI_shape_size_t* offsets;
|
|
||||||
char const* ptr;
|
|
||||||
|
|
||||||
ptr = json->_data.data;
|
|
||||||
n = * (TRI_shape_length_list_t*) ptr;
|
|
||||||
|
|
||||||
ptr += sizeof(TRI_shape_length_list_t);
|
ptr += sizeof(TRI_shape_length_list_t);
|
||||||
sids = (TRI_shape_sid_t*) ptr;
|
TRI_shape_sid_t* sids = (TRI_shape_sid_t*) ptr;
|
||||||
|
|
||||||
ptr += n * sizeof(TRI_shape_sid_t);
|
ptr += n * sizeof(TRI_shape_sid_t);
|
||||||
offsets = (TRI_shape_size_t*) ptr;
|
TRI_shape_size_t* offsets = (TRI_shape_size_t*) ptr;
|
||||||
|
|
||||||
result->_sid = sids[position];
|
result->_sid = sids[position];
|
||||||
result->_data.data = ((char*) json->_data.data) + offsets[position];
|
result->_data.data = ((char*) json->_data.data) + offsets[position];
|
||||||
|
@ -2441,19 +2405,15 @@ bool TRI_AtHomogeneousListShapedJson (TRI_homogeneous_list_shape_t const* shape,
|
||||||
TRI_shaped_json_t const* json,
|
TRI_shaped_json_t const* json,
|
||||||
size_t position,
|
size_t position,
|
||||||
TRI_shaped_json_t* result) {
|
TRI_shaped_json_t* result) {
|
||||||
TRI_shape_length_list_t n;
|
char const* ptr = json->_data.data;
|
||||||
TRI_shape_size_t* offsets;
|
TRI_shape_length_list_t n = * (TRI_shape_length_list_t*) ptr;
|
||||||
char const* ptr;
|
|
||||||
|
|
||||||
ptr = json->_data.data;
|
|
||||||
n = * (TRI_shape_length_list_t*) ptr;
|
|
||||||
|
|
||||||
if (n <= position) {
|
if (n <= position) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr += sizeof(TRI_shape_length_list_t);
|
ptr += sizeof(TRI_shape_length_list_t);
|
||||||
offsets = (TRI_shape_size_t*) ptr;
|
TRI_shape_size_t* offsets = (TRI_shape_size_t*) ptr;
|
||||||
|
|
||||||
result->_sid = shape->_sidEntry;
|
result->_sid = shape->_sidEntry;
|
||||||
result->_data.data = ((char*) json->_data.data) + offsets[position];
|
result->_data.data = ((char*) json->_data.data) + offsets[position];
|
||||||
|
@ -2479,11 +2439,8 @@ bool TRI_AtHomogeneousSizedListShapedJson (TRI_homogeneous_sized_list_shape_t co
|
||||||
TRI_shaped_json_t const* json,
|
TRI_shaped_json_t const* json,
|
||||||
size_t position,
|
size_t position,
|
||||||
TRI_shaped_json_t* result) {
|
TRI_shaped_json_t* result) {
|
||||||
TRI_shape_length_list_t n;
|
char* ptr = json->_data.data;
|
||||||
char* ptr;
|
TRI_shape_length_list_t n = * (TRI_shape_length_list_t*) ptr;
|
||||||
|
|
||||||
ptr = json->_data.data;
|
|
||||||
n = * (TRI_shape_length_list_t*) ptr;
|
|
||||||
|
|
||||||
if (n <= position) {
|
if (n <= position) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2504,8 +2461,8 @@ bool TRI_AtHomogeneousSizedListShapedJson (TRI_homogeneous_sized_list_shape_t co
|
||||||
/// variables passed by reference
|
/// variables passed by reference
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool TRI_StringValueShapedJson (const TRI_shape_t* const shape,
|
bool TRI_StringValueShapedJson (TRI_shape_t const* shape,
|
||||||
const char* data,
|
char const* data,
|
||||||
char** value,
|
char** value,
|
||||||
size_t* length) {
|
size_t* length) {
|
||||||
if (shape->_type == TRI_SHAPE_SHORT_STRING) {
|
if (shape->_type == TRI_SHAPE_SHORT_STRING) {
|
||||||
|
|
|
@ -1050,8 +1050,8 @@ void TRI_PrintShape (struct TRI_shaper_s* shaper,
|
||||||
/// variables passed by reference
|
/// variables passed by reference
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool TRI_StringValueShapedJson (const TRI_shape_t* const,
|
bool TRI_StringValueShapedJson (TRI_shape_t const*,
|
||||||
const char*,
|
char const*,
|
||||||
char**,
|
char**,
|
||||||
size_t*);
|
size_t*);
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ shape_cache_t;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int FillShapeValueNull (TRI_shaper_t* shaper,
|
static int FillShapeValueNull (TRI_shaper_t* shaper,
|
||||||
TRI_shape_value_t* dst) {
|
TRI_shape_value_t* dst) {
|
||||||
dst->_type = TRI_SHAPE_NULL;
|
dst->_type = TRI_SHAPE_NULL;
|
||||||
dst->_sid = BasicShapes::TRI_SHAPE_SID_NULL;
|
dst->_sid = BasicShapes::TRI_SHAPE_SID_NULL;
|
||||||
dst->_fixedSized = true;
|
dst->_fixedSized = true;
|
||||||
|
@ -214,7 +214,7 @@ static int FillShapeValueString (TRI_shaper_t* shaper,
|
||||||
|
|
||||||
TRI_Utf8ValueNFC str(TRI_UNKNOWN_MEM_ZONE, json);
|
TRI_Utf8ValueNFC str(TRI_UNKNOWN_MEM_ZONE, json);
|
||||||
|
|
||||||
if (*str == 0) {
|
if (*str == nullptr) {
|
||||||
// empty string
|
// empty string
|
||||||
dst->_type = TRI_SHAPE_SHORT_STRING;
|
dst->_type = TRI_SHAPE_SHORT_STRING;
|
||||||
dst->_sid = BasicShapes::TRI_SHAPE_SID_SHORT_STRING;
|
dst->_sid = BasicShapes::TRI_SHAPE_SID_SHORT_STRING;
|
||||||
|
@ -848,12 +848,45 @@ static int FillShapeValueJson (v8::Isolate* isolate,
|
||||||
vector<v8::Handle<v8::Object>>& seenObjects,
|
vector<v8::Handle<v8::Object>>& seenObjects,
|
||||||
bool create) {
|
bool create) {
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
|
|
||||||
if (json->IsRegExp() || json->IsFunction() || json->IsExternal()) {
|
if (json->IsRegExp() || json->IsFunction() || json->IsExternal()) {
|
||||||
LOG_TRACE("shaper failed because regexp/function/external/date object cannot be converted");
|
LOG_TRACE("shaper failed because regexp/function/external/date object cannot be converted");
|
||||||
return TRI_ERROR_BAD_PARAMETER;
|
return TRI_ERROR_BAD_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json->IsObject() && ! json->IsArray()) {
|
if (json->IsNull() || json->IsUndefined()) {
|
||||||
|
return FillShapeValueNull(shaper, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsBoolean()) {
|
||||||
|
return FillShapeValueBoolean(shaper, dst, json->ToBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsBooleanObject()) {
|
||||||
|
return FillShapeValueBoolean(shaper, dst, v8::Handle<v8::BooleanObject>::Cast(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsNumber()) {
|
||||||
|
return FillShapeValueNumber(shaper, dst, json->ToNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsNumberObject()) {
|
||||||
|
return FillShapeValueNumber(shaper, dst, v8::Handle<v8::NumberObject>::Cast(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsString()) {
|
||||||
|
return FillShapeValueString(shaper, dst, json->ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsStringObject()) {
|
||||||
|
return FillShapeValueString(shaper, dst, v8::Handle<v8::StringObject>::Cast(json)->ValueOf());
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (json->IsArray()) {
|
||||||
|
return FillShapeValueList(isolate, shaper, dst, v8::Handle<v8::Array>::Cast(json), level, seenHashes, seenObjects, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json->IsObject()) {
|
||||||
v8::Handle<v8::Object> o = json->ToObject();
|
v8::Handle<v8::Object> o = json->ToObject();
|
||||||
v8::Handle<v8::String> toJsonString = TRI_V8_ASCII_STRING("toJSON");
|
v8::Handle<v8::String> toJsonString = TRI_V8_ASCII_STRING("toJSON");
|
||||||
if (o->Has(toJsonString)) {
|
if (o->Has(toJsonString)) {
|
||||||
|
@ -876,11 +909,8 @@ static int FillShapeValueJson (v8::Isolate* isolate,
|
||||||
int hash = o->GetIdentityHash();
|
int hash = o->GetIdentityHash();
|
||||||
|
|
||||||
if (seenHashes.find(hash) != seenHashes.end()) {
|
if (seenHashes.find(hash) != seenHashes.end()) {
|
||||||
// LOG_TRACE("found hash %d", hash);
|
|
||||||
|
|
||||||
for (auto it = seenObjects.begin(); it != seenObjects.end(); ++it) {
|
for (auto it = seenObjects.begin(); it != seenObjects.end(); ++it) {
|
||||||
if (json->StrictEquals(*it)) {
|
if (json->StrictEquals(*it)) {
|
||||||
LOG_TRACE("found duplicate for hash %d", hash);
|
|
||||||
return TRI_ERROR_ARANGO_SHAPER_FAILED;
|
return TRI_ERROR_ARANGO_SHAPER_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -890,41 +920,6 @@ static int FillShapeValueJson (v8::Isolate* isolate,
|
||||||
}
|
}
|
||||||
|
|
||||||
seenObjects.push_back(o);
|
seenObjects.push_back(o);
|
||||||
}
|
|
||||||
|
|
||||||
if (json->IsNull() || json->IsUndefined()) {
|
|
||||||
return FillShapeValueNull(shaper, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsBoolean()) {
|
|
||||||
return FillShapeValueBoolean(shaper, dst, json->ToBoolean());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsBooleanObject()) {
|
|
||||||
return FillShapeValueBoolean(shaper, dst, v8::Handle<v8::BooleanObject>::Cast(json));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsNumber()) {
|
|
||||||
return FillShapeValueNumber(shaper, dst, json->ToNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsNumberObject()) {
|
|
||||||
return FillShapeValueNumber(shaper, dst, v8::Handle<v8::NumberObject>::Cast(json));
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsString()) {
|
|
||||||
return FillShapeValueString(shaper, dst, json->ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsStringObject()) {
|
|
||||||
return FillShapeValueString(shaper, dst, v8::Handle<v8::StringObject>::Cast(json)->ValueOf());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsArray()) {
|
|
||||||
return FillShapeValueList(isolate, shaper, dst, v8::Handle<v8::Array>::Cast(json), level, seenHashes, seenObjects, create);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (json->IsObject()) {
|
|
||||||
int res = FillShapeValueArray(isolate, shaper, dst, json->ToObject(), level, seenHashes, seenObjects, create);
|
int res = FillShapeValueArray(isolate, shaper, dst, json->ToObject(), level, seenHashes, seenObjects, create);
|
||||||
seenObjects.pop_back();
|
seenObjects.pop_back();
|
||||||
// cannot remove hash value from seenHashes because multiple objects might have the same
|
// cannot remove hash value from seenHashes because multiple objects might have the same
|
||||||
|
@ -957,9 +952,7 @@ static v8::Handle<v8::Value> JsonShapeDataBoolean (v8::Isolate* isolate,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
bool v;
|
bool v = (* (TRI_shape_boolean_t const*) data) != 0;
|
||||||
|
|
||||||
v = (* (TRI_shape_boolean_t const*) data) != 0;
|
|
||||||
|
|
||||||
return v8::Boolean::New(isolate, v);
|
return v8::Boolean::New(isolate, v);
|
||||||
}
|
}
|
||||||
|
@ -973,9 +966,7 @@ static v8::Handle<v8::Value> JsonShapeDataNumber (v8::Isolate* isolate,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
TRI_shape_number_t v;
|
TRI_shape_number_t v = * (TRI_shape_number_t const*) data;
|
||||||
|
|
||||||
v = * (TRI_shape_number_t const*) data;
|
|
||||||
|
|
||||||
return v8::Number::New(isolate, v);
|
return v8::Number::New(isolate, v);
|
||||||
}
|
}
|
||||||
|
@ -989,9 +980,7 @@ static v8::Handle<v8::Value> JsonShapeDataShortString (v8::Isolate* isolate,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
TRI_shape_length_short_string_t l;
|
TRI_shape_length_short_string_t l = * (TRI_shape_length_short_string_t const*) data;
|
||||||
|
|
||||||
l = * (TRI_shape_length_short_string_t const*) data;
|
|
||||||
data += sizeof(TRI_shape_length_short_string_t);
|
data += sizeof(TRI_shape_length_short_string_t);
|
||||||
|
|
||||||
return TRI_V8_PAIR_STRING(data, l - 1);
|
return TRI_V8_PAIR_STRING(data, l - 1);
|
||||||
|
@ -1006,9 +995,7 @@ static v8::Handle<v8::Value> JsonShapeDataLongString (v8::Isolate* isolate,
|
||||||
TRI_shape_t const* shape,
|
TRI_shape_t const* shape,
|
||||||
char const* data,
|
char const* data,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
TRI_shape_length_long_string_t l;
|
TRI_shape_length_long_string_t l = * (TRI_shape_length_long_string_t const*) data;
|
||||||
|
|
||||||
l = * (TRI_shape_length_long_string_t const*) data;
|
|
||||||
data += sizeof(TRI_shape_length_long_string_t);
|
data += sizeof(TRI_shape_length_long_string_t);
|
||||||
|
|
||||||
return TRI_V8_PAIR_STRING(data, l - 1);
|
return TRI_V8_PAIR_STRING(data, l - 1);
|
||||||
|
@ -1447,6 +1434,7 @@ static v8::Handle<v8::Value> JsonShapeData (v8::Isolate* isolate,
|
||||||
case TRI_SHAPE_HOMOGENEOUS_SIZED_LIST:
|
case TRI_SHAPE_HOMOGENEOUS_SIZED_LIST:
|
||||||
return JsonShapeDataHomogeneousSizedList(isolate, shaper, shape, data, size);
|
return JsonShapeDataHomogeneousSizedList(isolate, shaper, shape, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
v8::EscapableHandleScope scope(isolate);
|
v8::EscapableHandleScope scope(isolate);
|
||||||
return scope.Escape<v8::Value>(v8::Null(isolate));
|
return scope.Escape<v8::Value>(v8::Null(isolate));
|
||||||
|
@ -1852,7 +1840,6 @@ static int ObjectToJson (v8::Isolate* isolate,
|
||||||
for (auto it : seenObjects) {
|
for (auto it : seenObjects) {
|
||||||
if (parameter->StrictEquals(it)) {
|
if (parameter->StrictEquals(it)) {
|
||||||
// object is recursive
|
// object is recursive
|
||||||
LOG_TRACE("found duplicate for hash %d", hash);
|
|
||||||
TRI_InitNullJson(result);
|
TRI_InitNullJson(result);
|
||||||
return TRI_ERROR_BAD_PARAMETER;
|
return TRI_ERROR_BAD_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue