1
0
Fork 0

don't copy bytecode after creation

This commit is contained in:
Jan Steemann 2014-05-17 12:05:15 +02:00
parent bed37d7d11
commit 0a2e155f12
1 changed files with 8 additions and 35 deletions

View File

@ -38,11 +38,6 @@
// --SECTION-- private functions // --SECTION-- private functions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Json
/// @{
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief computes a byte-code sequence /// @brief computes a byte-code sequence
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -244,15 +239,12 @@ static bool BytecodeShapeAccessor (TRI_shaper_t* shaper, TRI_shape_access_t* acc
} }
accessor->_shape = shape; accessor->_shape = shape;
accessor->_code = static_cast<void const**>(TRI_Allocate(shaper->_memoryZone, ops._length * sizeof(void*), false));
if (accessor->_code == NULL) { // steal buffer from ops vector so we don't need to copy it
LOG_ERROR("out of memory"); accessor->_code = const_cast<void const**>(ops._buffer);
TRI_DestroyVectorPointer(&ops);
return false;
}
memcpy(CONST_CAST(accessor->_code), ops._buffer, ops._length * sizeof(void*)); // inform the vector that we took over ownership
ops._buffer = NULL;
TRI_DestroyVectorPointer(&ops); TRI_DestroyVectorPointer(&ops);
return true; return true;
@ -278,7 +270,7 @@ static bool ExecuteBytecodeShapeAccessor (TRI_shape_access_t const* accessor,
while (true) { while (true) {
TRI_shape_ac_bc_e op = *(TRI_shape_ac_bc_e*) ops; TRI_shape_ac_bc_e op = *(TRI_shape_ac_bc_e*) ops;
ops++; ++ops;
switch (op) { switch (op) {
case TRI_SHAPE_AC_DONE: case TRI_SHAPE_AC_DONE:
@ -311,19 +303,10 @@ static bool ExecuteBytecodeShapeAccessor (TRI_shape_access_t const* accessor,
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public functions // --SECTION-- public functions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Json
/// @{
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief free a shape accessor /// @brief free a shape accessor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -374,16 +357,10 @@ TRI_shape_access_t* TRI_ShapeAccessor (TRI_shaper_t* shaper,
bool TRI_ExecuteShapeAccessor (TRI_shape_access_t const* accessor, bool TRI_ExecuteShapeAccessor (TRI_shape_access_t const* accessor,
TRI_shaped_json_t const* shaped, TRI_shaped_json_t const* shaped,
TRI_shaped_json_t* result) { TRI_shaped_json_t* result) {
void* begin; void* begin = shaped->_data.data;
void* end; void* end = ((char*) begin) + shaped->_data.length;
bool ok;
begin = shaped->_data.data; if (! ExecuteBytecodeShapeAccessor(accessor, &begin, &end)) {
end = ((char*) begin) + shaped->_data.length;
ok = ExecuteBytecodeShapeAccessor(accessor, &begin, &end);
if (! ok) {
return false; return false;
} }
@ -447,10 +424,6 @@ void TRI_PrintShapeAccessor (TRI_shape_access_t* accessor) {
} }
} }
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables: // Local Variables:
// mode: outline-minor // mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}" // outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"