mirror of https://gitee.com/bigwinds/arangodb
some small optimizations
This commit is contained in:
parent
7abcfab41a
commit
c05421e1aa
|
@ -246,9 +246,9 @@ int RestImportHandler::handleSingleDocument(SingleCollectionTransaction& trx,
|
|||
}
|
||||
|
||||
try {
|
||||
arangodb::basics::VelocyPackHelper::checkAndGetStringValue(
|
||||
arangodb::basics::VelocyPackHelper::ensureStringValue(
|
||||
slice, StaticStrings::FromString);
|
||||
arangodb::basics::VelocyPackHelper::checkAndGetStringValue(
|
||||
arangodb::basics::VelocyPackHelper::ensureStringValue(
|
||||
slice, StaticStrings::ToString);
|
||||
} catch (arangodb::basics::Exception const&) {
|
||||
std::string part = VPackDumper::toString(slice);
|
||||
|
@ -429,20 +429,18 @@ bool RestImportHandler::createFromJson(std::string const& type) {
|
|||
continue;
|
||||
}
|
||||
|
||||
TRI_ASSERT(ptr != nullptr);
|
||||
oldPtr = ptr;
|
||||
|
||||
tmpBuilder.clear();
|
||||
if (pos != nullptr) {
|
||||
// non-empty line
|
||||
*(const_cast<char*>(pos)) = '\0';
|
||||
TRI_ASSERT(ptr != nullptr);
|
||||
oldPtr = ptr;
|
||||
parseVelocyPackLine(tmpBuilder, ptr, pos, success);
|
||||
ptr = pos + 1;
|
||||
} else {
|
||||
// last-line, non-empty
|
||||
TRI_ASSERT(pos == nullptr);
|
||||
TRI_ASSERT(ptr != nullptr);
|
||||
oldPtr = ptr;
|
||||
parseVelocyPackLine(tmpBuilder, ptr, success);
|
||||
parseVelocyPackLine(tmpBuilder, ptr, end, success);
|
||||
ptr = end;
|
||||
}
|
||||
|
||||
|
@ -492,13 +490,12 @@ bool RestImportHandler::createFromJson(std::string const& type) {
|
|||
return false;
|
||||
}
|
||||
|
||||
VPackValueLength const n = documents.length();
|
||||
VPackBuilder lineBuilder;
|
||||
for (VPackValueLength i = 0; i < n; ++i) {
|
||||
VPackSlice const slice = documents.at(i);
|
||||
VPackArrayIterator it(documents);
|
||||
|
||||
res = handleSingleDocument(trx, lineBuilder, result, babies, slice, isEdgeCollection,
|
||||
static_cast<size_t>(i + 1));
|
||||
while (it.valid()) {
|
||||
res = handleSingleDocument(trx, lineBuilder, result, babies, it.value(), isEdgeCollection,
|
||||
static_cast<size_t>(it.index() + 1));
|
||||
|
||||
if (res.fail()) {
|
||||
if (complete) {
|
||||
|
@ -508,6 +505,8 @@ bool RestImportHandler::createFromJson(std::string const& type) {
|
|||
|
||||
res = TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
it.next();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,14 +596,12 @@ bool RestImportHandler::createFromVPack(std::string const& type) {
|
|||
return false;
|
||||
}
|
||||
|
||||
VPackValueLength const n = documents.length();
|
||||
|
||||
VPackBuilder lineBuilder;
|
||||
for (VPackValueLength i = 0; i < n; ++i) {
|
||||
VPackSlice const slice = documents.at(i);
|
||||
|
||||
res = handleSingleDocument(trx, lineBuilder, result, babies, slice, isEdgeCollection,
|
||||
static_cast<size_t>(i + 1));
|
||||
VPackArrayIterator it(documents);
|
||||
while (it.valid()) {
|
||||
res = handleSingleDocument(trx, lineBuilder, result, babies, it.value(), isEdgeCollection,
|
||||
static_cast<size_t>(it.index() + 1));
|
||||
|
||||
if (res.fail()) {
|
||||
if (complete) {
|
||||
|
@ -614,6 +611,8 @@ bool RestImportHandler::createFromVPack(std::string const& type) {
|
|||
|
||||
res = TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
it.next();
|
||||
}
|
||||
|
||||
babies.close();
|
||||
|
@ -1042,28 +1041,12 @@ void RestImportHandler::generateDocumentsCreated(
|
|||
/// @brief parse a single document line
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestImportHandler::parseVelocyPackLine(
|
||||
VPackBuilder& builder,
|
||||
std::string const& line, bool& success) {
|
||||
try {
|
||||
success = true;
|
||||
VPackParser parser(builder);
|
||||
parser.parse(line);
|
||||
} catch (VPackException const&) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parse a single document line
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestImportHandler::parseVelocyPackLine(VPackBuilder& builder,
|
||||
char const* start, char const* end, bool& success) {
|
||||
try {
|
||||
success = true;
|
||||
VPackParser parser(builder);
|
||||
parser.parse(start,std::distance(start, end));
|
||||
parser.parse(start, std::distance(start, end));
|
||||
} catch (std::exception const&) {
|
||||
// The line is invalid and could not be transformed into a string
|
||||
success = false;
|
||||
|
|
|
@ -141,12 +141,6 @@ class RestImportHandler : public RestVocbaseBaseHandler {
|
|||
/// @brief parses a string
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseVelocyPackLine(VPackBuilder&, std::string const&, bool&);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parses a string
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseVelocyPackLine(VPackBuilder&, char const*, char const*, bool&);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -675,7 +675,7 @@ void transaction::Methods::buildDocumentIdentity(
|
|||
LogicalCollection* collection, VPackBuilder& builder, TRI_voc_cid_t cid,
|
||||
StringRef const& key, TRI_voc_rid_t rid, TRI_voc_rid_t oldRid,
|
||||
ManagedDocumentResult const* oldDoc, ManagedDocumentResult const* newDoc) {
|
||||
std::string temp;
|
||||
std::string temp; // TODO: pass a string into this function
|
||||
temp.reserve(64);
|
||||
|
||||
if (_state->isRunningInCluster()) {
|
||||
|
|
|
@ -488,6 +488,20 @@ std::string VelocyPackHelper::checkAndGetStringValue(VPackSlice const& slice,
|
|||
return sub.copyString();
|
||||
}
|
||||
|
||||
void VelocyPackHelper::ensureStringValue(VPackSlice const& slice,
|
||||
std::string const& name) {
|
||||
TRI_ASSERT(slice.isObject());
|
||||
if (!slice.hasKey(name)) {
|
||||
std::string msg = "The attribute '" + name + "' was not found.";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg);
|
||||
}
|
||||
VPackSlice const sub = slice.get(name);
|
||||
if (!sub.isString()) {
|
||||
std::string msg = "The attribute '" + name + "' is not a string.";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a string value, or the default value if it is not a string
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -282,9 +282,16 @@ class VelocyPackHelper {
|
|||
|
||||
static std::string checkAndGetStringValue(VPackSlice const&, char const*);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ensures a sub-element is of type string
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string checkAndGetStringValue(VPackSlice const&,
|
||||
std::string const&);
|
||||
|
||||
static void ensureStringValue(VPackSlice const&,
|
||||
std::string const&);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns a Numeric sub-element, or throws if <name> does not exist
|
||||
/// or it is not a Number
|
||||
|
|
Loading…
Reference in New Issue