mirror of https://gitee.com/bigwinds/arangodb
calculate lengths only once during dump()
This commit is contained in:
parent
7783bc6687
commit
e31a91affe
|
@ -107,14 +107,14 @@ int JsonLegend::addAttributeId (TRI_shape_aid_t aid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* p = _shaper->lookupAttributeId(_shaper, aid);
|
char const* p = _shaper->lookupAttributeId(_shaper, aid);
|
||||||
if (0 == p) {
|
if (nullptr == p) {
|
||||||
return TRI_ERROR_AID_NOT_FOUND;
|
return TRI_ERROR_AID_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
_have_attribute.insert(aid);
|
_have_attribute.insert(it, aid);
|
||||||
size_t len = strlen(p);
|
size_t len = strlen(p);
|
||||||
_attribs.emplace_back(aid, _att_data.length());
|
_attribs.emplace_back(aid, _att_data.length());
|
||||||
_att_data.appendText(p, len+1); // including the zero byte
|
_att_data.appendText(p, len + 1); // including the zero byte
|
||||||
return TRI_ERROR_NO_ERROR;
|
return TRI_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ int JsonLegend::addShape (TRI_shape_sid_t sid,
|
||||||
|
|
||||||
int res = TRI_ERROR_NO_ERROR;
|
int res = TRI_ERROR_NO_ERROR;
|
||||||
|
|
||||||
TRI_shape_t const* shape = 0;
|
TRI_shape_t const* shape = nullptr;
|
||||||
|
|
||||||
// First the trivial cases:
|
// First the trivial cases:
|
||||||
if (sid < TRI_FirstCustomShapeIdShaper()) {
|
if (sid < TRI_FirstCustomShapeIdShaper()) {
|
||||||
|
@ -141,13 +141,13 @@ int JsonLegend::addShape (TRI_shape_sid_t sid,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shape = _shaper->lookupShapeId(_shaper, sid);
|
shape = _shaper->lookupShapeId(_shaper, sid);
|
||||||
if (0 == shape) {
|
if (nullptr == shape) {
|
||||||
return TRI_ERROR_LEGEND_INCOMPLETE;
|
return TRI_ERROR_LEGEND_INCOMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unordered_set<TRI_shape_sid_t>::const_iterator it = _have_shape.find(sid);
|
unordered_set<TRI_shape_sid_t>::const_iterator it = _have_shape.find(sid);
|
||||||
if (it == _have_shape.end()) {
|
if (it == _have_shape.end()) {
|
||||||
_have_shape.insert(sid);
|
_have_shape.insert(it, sid);
|
||||||
Shape sh(sid, _shape_data.length(), shape->_size);
|
Shape sh(sid, _shape_data.length(), shape->_size);
|
||||||
_shapes.push_back(sh);
|
_shapes.push_back(sh);
|
||||||
_shape_data.appendText( reinterpret_cast<char const*>(shape),
|
_shape_data.appendText( reinterpret_cast<char const*>(shape),
|
||||||
|
@ -303,13 +303,15 @@ void JsonLegend::dump (void* buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the length of the string data to socle for second table:
|
// Add the length of the string data to socle for second table:
|
||||||
socle += roundup8(_att_data.length());
|
size_t const attDataLength = _att_data.length();
|
||||||
|
socle += roundup8(attDataLength);
|
||||||
|
|
||||||
// shape table:
|
// shape table:
|
||||||
|
size_t const n = _shapes.size();
|
||||||
p = reinterpret_cast<TRI_shape_size_t*>(a);
|
p = reinterpret_cast<TRI_shape_size_t*>(a);
|
||||||
*p++ = _shapes.size();
|
*p++ = n;
|
||||||
Shape* s = reinterpret_cast<Shape*>(p);
|
Shape* s = reinterpret_cast<Shape*>(p);
|
||||||
for (i = 0; i < _shapes.size(); i++) {
|
for (i = 0; i < n; i++) {
|
||||||
_shapes[i].offset += socle;
|
_shapes[i].offset += socle;
|
||||||
*s++ = _shapes[i];
|
*s++ = _shapes[i];
|
||||||
_shapes[i].offset -= socle;
|
_shapes[i].offset -= socle;
|
||||||
|
@ -317,17 +319,18 @@ void JsonLegend::dump (void* buf) {
|
||||||
|
|
||||||
// Attribute ID string data:
|
// Attribute ID string data:
|
||||||
char* c = reinterpret_cast<char*>(s);
|
char* c = reinterpret_cast<char*>(s);
|
||||||
memcpy(c, _att_data.c_str(), _att_data.length());
|
memcpy(c, _att_data.c_str(), attDataLength);
|
||||||
i = roundup8(_att_data.length());
|
i = roundup8(attDataLength);
|
||||||
if (i > _att_data.length()) {
|
if (i > attDataLength) {
|
||||||
memset( c + _att_data.length(), 0, i-_att_data.length());
|
memset(c + attDataLength, 0, i - attDataLength);
|
||||||
}
|
}
|
||||||
c += i;
|
c += i;
|
||||||
|
|
||||||
// Shape data:
|
// Shape data:
|
||||||
memcpy(c, _shape_data.c_str(), _shape_data.length());
|
size_t const shapeDataLength = _shape_data.length();
|
||||||
i = roundup8(_shape_data.length());
|
memcpy(c, _shape_data.c_str(), shapeDataLength);
|
||||||
if (i > _shape_data.length()) {
|
i = roundup8(shapeDataLength);
|
||||||
memset( c + _shape_data.length(), 0, i-_shape_data.length());
|
if (i > shapeDataLength) {
|
||||||
|
memset(c + shapeDataLength, 0, i - shapeDataLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue