mirror of https://gitee.com/bigwinds/arangodb
allow using a few more bytes for indexed slice values
This commit is contained in:
parent
7cf218f3e9
commit
a5bbb8d084
|
@ -140,16 +140,40 @@ enum TRI_edge_direction_e {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief velocypack sub-object (for indexes, as part of TRI_index_element_t,
|
||||
/// if offset is non-zero, then it is an offset into the VelocyPack data in
|
||||
/// the data or WAL file. If offset is 0, then data contains the actual data
|
||||
/// in place.
|
||||
/// if the last byte in data[] is 0, then it is an offset into the VelocyPack
|
||||
/// data in the datafile or WAL file. If the last byte in data[] is 1, then
|
||||
/// value.data contains the actual VelocyPack data in place.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct TRI_vpack_sub_t {
|
||||
uint32_t offset;
|
||||
uint8_t data[8];
|
||||
union {
|
||||
uint8_t data[12];
|
||||
uint32_t offset;
|
||||
} value;
|
||||
|
||||
static constexpr size_t maxValueLength() noexcept {
|
||||
return sizeof(value.data) - 1;
|
||||
}
|
||||
|
||||
void setOffset(uint32_t offset) noexcept {
|
||||
value.offset = offset;
|
||||
value.data[maxValueLength()] = 0; // type = offset
|
||||
}
|
||||
|
||||
void setValue(uint8_t const* data, size_t length) noexcept {
|
||||
memcpy(&value.data[0], data, length);
|
||||
value.data[maxValueLength()] = 1; // type = value
|
||||
}
|
||||
|
||||
VPackSlice const slice(TRI_doc_mptr_t const* mptr) const;
|
||||
inline bool isOffset() const noexcept {
|
||||
return value.data[maxValueLength()] == 0;
|
||||
}
|
||||
|
||||
inline bool isValue() const noexcept {
|
||||
return value.data[maxValueLength()] == 1;
|
||||
}
|
||||
|
||||
VPackSlice slice(TRI_doc_mptr_t const* mptr) const;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -2293,12 +2293,11 @@ TRI_vocbase_t::getReplicationClients() {
|
|||
/// in place.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
VPackSlice const TRI_vpack_sub_t::slice(TRI_doc_mptr_t const* mptr) const {
|
||||
if (offset == 0) {
|
||||
return VPackSlice(data);
|
||||
} else {
|
||||
return VPackSlice(mptr->vpack() + offset);
|
||||
}
|
||||
VPackSlice TRI_vpack_sub_t::slice(TRI_doc_mptr_t const* mptr) const {
|
||||
if (isValue()) {
|
||||
return VPackSlice(&value.data[0]);
|
||||
}
|
||||
return VPackSlice(mptr->vpack() + value.offset);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2307,14 +2306,12 @@ VPackSlice const TRI_vpack_sub_t::slice(TRI_doc_mptr_t const* mptr) const {
|
|||
|
||||
void TRI_FillVPackSub(TRI_vpack_sub_t* sub,
|
||||
VPackSlice const base, VPackSlice const value) noexcept {
|
||||
if (value.byteSize() <= sizeof(sub->data)) {
|
||||
sub->offset = 0;
|
||||
memcpy(sub->data, value.start(), value.byteSize());
|
||||
if (value.byteSize() <= TRI_vpack_sub_t::maxValueLength()) {
|
||||
sub->setValue(value.start(), value.byteSize());
|
||||
} else {
|
||||
size_t off = value.start() - base.start();
|
||||
TRI_ASSERT(off <= UINT32_MAX);
|
||||
sub->offset = static_cast<uint32_t>(off);
|
||||
memset(sub->data, 0, sizeof(sub->data));
|
||||
sub->setOffset(static_cast<uint32_t>(off));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue