From 30525fccee7d320187355eddbfe6d68e57285f6d Mon Sep 17 00:00:00 2001 From: jsteemann Date: Tue, 10 May 2016 17:01:34 +0200 Subject: [PATCH] use StaticStrings --- arangod/Agency/State.cpp | 3 +- arangod/Aql/ClusterBlocks.cpp | 11 ++++--- arangod/Aql/Collection.cpp | 4 ++- arangod/Aql/Functions.cpp | 12 +++---- arangod/Aql/OptimizerRules.cpp | 6 ++-- arangod/Cluster/ClusterInfo.cpp | 2 +- arangod/Cluster/ClusterInfo.h | 4 +-- arangod/Cluster/ClusterMethods.cpp | 24 +++++++------- arangod/Cluster/ClusterTraverser.cpp | 10 +++--- arangod/HttpServer/PathHandler.cpp | 12 +++---- arangod/Replication/ContinuousSyncer.cpp | 8 ++--- arangod/Replication/InitialSyncer.cpp | 40 ++++++++++++------------ arangod/RestHandler/RestBatchHandler.cpp | 5 +-- arangod/RestServer/VocbaseContext.cpp | 4 +-- arangod/V8Server/v8-actions.cpp | 8 ++--- arangod/V8Server/v8-util.cpp | 6 ++-- arangod/V8Server/v8-vocindex.cpp | 2 +- arangosh/Benchmark/BenchmarkThread.h | 8 ++--- arangosh/V8Client/ArangoClientHelper.cpp | 2 +- lib/Basics/StaticStrings.cpp | 4 +++ lib/Basics/StaticStrings.h | 4 +++ 21 files changed, 90 insertions(+), 89 deletions(-) diff --git a/arangod/Agency/State.cpp b/arangod/Agency/State.cpp index c19434d151..e0ec58fbe7 100644 --- a/arangod/Agency/State.cpp +++ b/arangod/Agency/State.cpp @@ -34,6 +34,7 @@ #include #include "Aql/Query.h" +#include "Basics/StaticStrings.h" #include "Basics/VelocyPackHelper.h" #include "RestServer/QueryRegistryFeature.h" #include "Utils/OperationOptions.h" @@ -295,7 +296,7 @@ bool State::loadCollection(std::string const& name) { VPackSlice req = i.get("request"); tmp->append(req.startAs(), req.byteSize()); _log.push_back( - log_t(std::stoi(i.get(TRI_VOC_ATTRIBUTE_KEY).copyString()), + log_t(std::stoi(i.get(StaticStrings::KeyString).copyString()), static_cast(i.get("term").getUInt()), static_cast( i.get("leader").getUInt()), tmp)); diff --git a/arangod/Aql/ClusterBlocks.cpp b/arangod/Aql/ClusterBlocks.cpp index fea07af700..50b6a0a79b 100644 --- a/arangod/Aql/ClusterBlocks.cpp +++ b/arangod/Aql/ClusterBlocks.cpp @@ -26,6 +26,7 @@ #include "Aql/AqlValue.h" #include "Basics/Exceptions.h" #include "Basics/json-utilities.h" +#include "Basics/StaticStrings.h" #include "Basics/StringUtils.h" #include "Basics/StringBuffer.h" #include "Basics/VelocyPackHelper.h" @@ -981,7 +982,7 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) { static_cast(_exeNode) ->_allowKeyConversionToObject) { builder.openObject(); - builder.add(TRI_VOC_ATTRIBUTE_KEY, input); + builder.add(StaticStrings::KeyString, input); builder.close(); // clear the previous value @@ -1004,12 +1005,12 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) { if (_usesDefaultSharding) { // the collection is sharded by _key... - if (!hasCreatedKeyAttribute && !value.hasKey(TRI_VOC_ATTRIBUTE_KEY)) { + if (!hasCreatedKeyAttribute && !value.hasKey(StaticStrings::KeyString)) { // there is no _key attribute present, so we are responsible for // creating one VPackBuilder temp; temp.openObject(); - temp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(createKey())); + temp.add(StaticStrings::KeyString, VPackValue(createKey())); temp.close(); builder2 = VPackCollection::merge(input, temp.slice(), true); @@ -1024,14 +1025,14 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) { } else { // the collection is not sharded by _key - if (hasCreatedKeyAttribute || value.hasKey(TRI_VOC_ATTRIBUTE_KEY)) { + if (hasCreatedKeyAttribute || value.hasKey(StaticStrings::KeyString)) { // a _key was given, but user is not allowed to specify _key THROW_ARANGO_EXCEPTION(TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY); } VPackBuilder temp; temp.openObject(); - temp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(createKey())); + temp.add(StaticStrings::KeyString, VPackValue(createKey())); temp.close(); builder2 = VPackCollection::merge(input, temp.slice(), true); diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index 8ce8194544..6851da0278 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -22,6 +22,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "Collection.h" +#include "Basics/StaticStrings.h" #include "Basics/StringUtils.h" #include "Basics/Exceptions.h" #include "Cluster/ClusterInfo.h" @@ -34,6 +35,7 @@ #include #include +using namespace arangodb; using namespace arangodb::aql; /// @brief create a collection wrapper @@ -137,7 +139,7 @@ bool Collection::usesDefaultSharding() const { // check if collection shard keys are only _key std::vector sk(shardKeys()); - if (sk.size() != 1 || sk[0] != TRI_VOC_ATTRIBUTE_KEY) { + if (sk.size() != 1 || sk[0] != StaticStrings::KeyString) { return false; } return true; diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index 206888f576..3f0a92999c 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -1970,12 +1970,12 @@ AqlValue Functions::Neighbors(arangodb::aql::Query* query, splitCollection = true; } } else if (vertexInfo.isObject()) { - if (!vertexInfo.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { + if (!vertexInfo.hasKey(trx, StaticStrings::IdString)) { THROW_ARANGO_EXCEPTION_PARAMS( TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "NEIGHBORS"); } bool localMustDestroy; - AqlValue id = vertexInfo.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); + AqlValue id = vertexInfo.get(trx, StaticStrings::IdString, localMustDestroy, false); AqlValueGuard guard(id, localMustDestroy); if (!id.isString()) { @@ -2310,9 +2310,9 @@ AqlValue Functions::ParseIdentifier( AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0); std::string identifier; - if (value.isObject() && value.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { + if (value.isObject() && value.hasKey(trx, StaticStrings::IdString)) { bool localMustDestroy; - AqlValue s = value.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); + AqlValue s = value.get(trx, StaticStrings::IdString, localMustDestroy, false); AqlValueGuard guard(s, localMustDestroy); if (s.isString()) { @@ -3666,9 +3666,9 @@ AqlValue Functions::IsSameCollection( AqlValue value = ExtractFunctionParameterValue(trx, parameters, 1); std::string identifier; - if (value.isObject() && value.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { + if (value.isObject() && value.hasKey(trx, StaticStrings::IdString)) { bool localMustDestroy; - value = value.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); + value = value.get(trx, StaticStrings::IdString, localMustDestroy, false); AqlValueGuard guard(value, localMustDestroy); if (value.isString()) { diff --git a/arangod/Aql/OptimizerRules.cpp b/arangod/Aql/OptimizerRules.cpp index 0f6b702063..5b76e24b39 100644 --- a/arangod/Aql/OptimizerRules.cpp +++ b/arangod/Aql/OptimizerRules.cpp @@ -39,11 +39,11 @@ #include "Aql/Variable.h" #include "Aql/types.h" #include "Basics/AttributeNameParser.h" -#include "Basics/json-utilities.h" +#include "Basics/StaticStrings.h" #include "Utils/Transaction.h" +using namespace arangodb; using namespace arangodb::aql; -using Json = arangodb::basics::Json; using EN = arangodb::aql::ExecutionNode; /// @brief adds a SORT operation for IN right-hand side operands @@ -2794,7 +2794,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker { } // check the remove node's collection is sharded over _key std::vector shardKeys = rn->collection()->shardKeys(); - if (shardKeys.size() != 1 || shardKeys[0] != TRI_VOC_ATTRIBUTE_KEY) { + if (shardKeys.size() != 1 || shardKeys[0] != StaticStrings::KeyString) { break; // abort . . . } diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 66cf1fe4e4..e747d55dd6 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -2316,7 +2316,7 @@ int ClusterInfo::getResponsibleShard(CollectionID const& collectionID, shardKeysPtr = it2->second; usesDefaultShardingAttributes = shardKeysPtr->size() == 1 && - shardKeysPtr->at(0) == TRI_VOC_ATTRIBUTE_KEY; + shardKeysPtr->at(0) == StaticStrings::KeyString; found = true; break; // all OK } diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index 8b9be32b62..34068b603d 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -26,7 +26,7 @@ #define ARANGOD_CLUSTER_CLUSTER_INFO_H 1 #include "Basics/Common.h" -#include "Basics/JsonHelper.h" +#include "Basics/StaticStrings.h" #include "Basics/VelocyPackHelper.h" #include "Basics/Mutex.h" #include "Basics/ReadWriteLock.h" @@ -297,7 +297,7 @@ class CollectionInfo { TRI_ASSERT(firstElement.isString()); std::string shardKey = arangodb::basics::VelocyPackHelper::getStringValue(firstElement, ""); - return shardKey == TRI_VOC_ATTRIBUTE_KEY; + return shardKey == StaticStrings::KeyString; } ////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/Cluster/ClusterMethods.cpp b/arangod/Cluster/ClusterMethods.cpp index c10bcb635e..4158f80bed 100644 --- a/arangod/Cluster/ClusterMethods.cpp +++ b/arangod/Cluster/ClusterMethods.cpp @@ -277,7 +277,7 @@ static int distributeBabyOnShards( // attributes a bit further down the line when we have determined // the responsible shard. - VPackSlice keySlice = node.get(TRI_VOC_ATTRIBUTE_KEY); + VPackSlice keySlice = node.get(StaticStrings::KeyString); if (keySlice.isNone()) { // The user did not specify a key, let's create one: uint64_t uid = ci->uniqid(); @@ -410,7 +410,7 @@ bool shardKeysChanged(std::string const& dbname, std::string const& collname, std::vector const& shardKeys = c->shardKeys(); for (size_t i = 0; i < shardKeys.size(); ++i) { - if (shardKeys[i] == TRI_VOC_ATTRIBUTE_KEY) { + if (shardKeys[i] == StaticStrings::KeyString) { continue; } @@ -1262,8 +1262,8 @@ int getDocumentOnCoordinator( for (auto const& it : shardMap) { if (!useMultiple) { TRI_ASSERT(it.second.size() == 1); - if (!options.ignoreRevs && slice.hasKey(TRI_VOC_ATTRIBUTE_REV)) { - headers->emplace("if-match", slice.get(TRI_VOC_ATTRIBUTE_REV).copyString()); + if (!options.ignoreRevs && slice.hasKey(StaticStrings::RevString)) { + headers->emplace("if-match", slice.get(StaticStrings::RevString).copyString()); } // We send to single endpoint @@ -1271,7 +1271,7 @@ int getDocumentOnCoordinator( "shard:" + it.first, reqType, baseUrl + StringUtils::urlEncode(it.first) + "/" + StringUtils::urlEncode( - slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()) + + slice.get(StaticStrings::KeyString).copyString()) + optsUrlPart, body); requests[0].setHeaders(headers); @@ -1330,15 +1330,15 @@ int getDocumentOnCoordinator( auto shardList = ci->getShardList(collid); if (!useMultiple) { - if (!options.ignoreRevs && slice.hasKey(TRI_VOC_ATTRIBUTE_REV)) { - headers->emplace("if-match", slice.get(TRI_VOC_ATTRIBUTE_REV).copyString()); + if (!options.ignoreRevs && slice.hasKey(StaticStrings::RevString)) { + headers->emplace("if-match", slice.get(StaticStrings::RevString).copyString()); } for (auto const& shard : *shardList) { ClusterCommRequest req( "shard:" + shard, reqType, baseUrl + StringUtils::urlEncode(shard) + "/" + StringUtils::urlEncode( - slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()) + + slice.get(StaticStrings::KeyString).copyString()) + optsUrlPart, nullptr); auto headersCopy = @@ -1435,7 +1435,7 @@ static void insertIntoShardMap( // We only need add one resp. shard VPackBuilder partial; partial.openObject(); - partial.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(splitId[1])); + partial.add(StaticStrings::KeyString, VPackValue(splitId[1])); partial.close(); bool usesDefaultShardingAttributes; ShardID shardID; @@ -1554,7 +1554,7 @@ int getFilteredDocumentsOnCoordinator( } for (auto const& element : VPackArrayIterator(documents)) { std::string id = arangodb::basics::VelocyPackHelper::getStringValue( - element, TRI_VOC_ATTRIBUTE_ID, ""); + element, StaticStrings::IdString, ""); VPackBuilder tmp; tmp.add(element); result.emplace(id, tmp.steal()); @@ -1815,7 +1815,7 @@ int modifyDocumentOnCoordinator( requests.emplace_back( "shard:" + it.first, reqType, baseUrl + StringUtils::urlEncode(it.first) + "/" + - slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString() + optsUrlPart, + slice.get(StaticStrings::KeyString).copyString() + optsUrlPart, body); } else { reqBuilder.clear(); @@ -1871,7 +1871,7 @@ int modifyDocumentOnCoordinator( auto body = std::make_shared(slice.toJson()); auto shardList = ci->getShardList(collid); if (!useMultiple) { - std::string key = slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); + std::string key = slice.get(StaticStrings::KeyString).copyString(); for (auto const& shard : *shardList) { requests.emplace_back( "shard:" + shard, reqType, diff --git a/arangod/Cluster/ClusterTraverser.cpp b/arangod/Cluster/ClusterTraverser.cpp index 07ef21ed58..c0fe5ecc7e 100644 --- a/arangod/Cluster/ClusterTraverser.cpp +++ b/arangod/Cluster/ClusterTraverser.cpp @@ -76,11 +76,11 @@ bool ClusterTraverser::VertexGetter::operator()(std::string const& edgeId, auto it = _traverser->_edges.find(edgeId); if (it != _traverser->_edges.end()) { VPackSlice slice(it->second->data()); - std::string from = slice.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); + std::string from = slice.get(StaticStrings::FromString).copyString(); if (from != vertexId) { result = from; } else { - std::string to = slice.get(TRI_VOC_ATTRIBUTE_TO).copyString(); + std::string to = slice.get(StaticStrings::ToString).copyString(); result = to; } auto exp = _traverser->_expressions->find(depth); @@ -155,14 +155,14 @@ void ClusterTraverser::EdgeGetter::operator()(std::string const& startVertex, std::unordered_set verticesToFetch; for (auto const& edge : VPackArrayIterator(edgesSlice)) { std::string edgeId = arangodb::basics::VelocyPackHelper::getStringValue( - edge, TRI_VOC_ATTRIBUTE_ID, ""); + edge, StaticStrings::IdString.c_str(), ""); std::string fromId = arangodb::basics::VelocyPackHelper::getStringValue( - edge, TRI_VOC_ATTRIBUTE_FROM, ""); + edge, StaticStrings::FromString.c_str(), ""); if (_traverser->_vertices.find(fromId) == _traverser->_vertices.end()) { verticesToFetch.emplace(std::move(fromId)); } std::string toId = arangodb::basics::VelocyPackHelper::getStringValue( - edge, TRI_VOC_ATTRIBUTE_TO, ""); + edge, StaticStrings::ToString.c_str(), ""); if (_traverser->_vertices.find(toId) == _traverser->_vertices.end()) { verticesToFetch.emplace(std::move(toId)); } diff --git a/arangod/HttpServer/PathHandler.cpp b/arangod/HttpServer/PathHandler.cpp index be97cb88e6..a159bc2ca9 100644 --- a/arangod/HttpServer/PathHandler.cpp +++ b/arangod/HttpServer/PathHandler.cpp @@ -32,6 +32,10 @@ #include "Rest/HttpResponse.h" using namespace arangodb::basics; + +static std::string const AllowedChars = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890. +-_="; + namespace arangodb { namespace rest { @@ -62,9 +66,6 @@ PathHandler::PathHandler(HttpRequest* request, Options const* options) // ----------------------------------------------------------------------------- HttpHandler::status_t PathHandler::execute() { - static std::string const allowed = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890. +-_="; - std::vector names = _request->suffix(); std::string name = path; std::string last = ""; @@ -113,7 +114,7 @@ HttpHandler::status_t PathHandler::execute() { return status_t(HANDLER_DONE); } - std::string::size_type sc = next.find_first_not_of(allowed); + std::string::size_type sc = next.find_first_not_of(AllowedChars); if (sc != std::string::npos) { LOG(WARN) << "file '" << name << "' contains illegal character"; @@ -170,8 +171,7 @@ HttpHandler::status_t PathHandler::execute() { if (cacheMaxAge > 0 && _request->requestType() == GeneralRequest::RequestType::GET) { // yes, then set a pro-caching header - static std::string const cacheControl = "cache-control"; - _response->setHeaderNC(cacheControl, maxAgeHeader); + _response->setHeaderNC(StaticStrings::CacheControl, maxAgeHeader); } std::string::size_type d = last.find_last_of('.'); diff --git a/arangod/Replication/ContinuousSyncer.cpp b/arangod/Replication/ContinuousSyncer.cpp index c11ea963be..bb048c4823 100644 --- a/arangod/Replication/ContinuousSyncer.cpp +++ b/arangod/Replication/ContinuousSyncer.cpp @@ -511,7 +511,7 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type, } // extract "key" - VPackSlice const key = doc.get(TRI_VOC_ATTRIBUTE_KEY); + VPackSlice const key = doc.get(StaticStrings::KeyString); if (!key.isString()) { errorMsg = "invalid document key format"; @@ -519,7 +519,7 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type, } // extract "rev" - VPackSlice const rev = doc.get(TRI_VOC_ATTRIBUTE_REV); + VPackSlice const rev = doc.get(StaticStrings::RevString); if (!rev.isString()) { errorMsg = "invalid document revision format"; @@ -528,8 +528,8 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type, VPackBuilder builder; builder.openObject(); - builder.add(TRI_VOC_ATTRIBUTE_KEY, key); - builder.add(TRI_VOC_ATTRIBUTE_REV, rev); + builder.add(StaticStrings::KeyString, key); + builder.add(StaticStrings::RevString, rev); builder.close(); VPackSlice const old = builder.slice(); diff --git a/arangod/Replication/InitialSyncer.cpp b/arangod/Replication/InitialSyncer.cpp index d0d12c0087..eaa59932f4 100644 --- a/arangod/Replication/InitialSyncer.cpp +++ b/arangod/Replication/InitialSyncer.cpp @@ -66,7 +66,7 @@ static bool BinarySearch(std::vector const& markers, TRI_ASSERT(position < markers.size()); VPackSlice const otherSlice(reinterpret_cast(markers.at(position))); - VPackSlice const otherKey = otherSlice.get(TRI_VOC_ATTRIBUTE_KEY); + VPackSlice const otherKey = otherSlice.get(StaticStrings::KeyString); int res = key.compare(otherKey.copyString()); @@ -539,12 +539,12 @@ int InitialSyncer::applyCollectionDump( } if (!doc.isNone()) { - VPackSlice value = doc.get(TRI_VOC_ATTRIBUTE_KEY); + VPackSlice value = doc.get(StaticStrings::KeyString); if (value.isString()) { key = value.copyString(); } - value = doc.get(TRI_VOC_ATTRIBUTE_REV); + value = doc.get(StaticStrings::RevString); if (value.isString()) { rev = value.copyString(); @@ -562,9 +562,9 @@ int InitialSyncer::applyCollectionDump( VPackBuilder oldBuilder; oldBuilder.openObject(); - oldBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); + oldBuilder.add(StaticStrings::KeyString, VPackValue(key)); if (!rev.empty()) { - oldBuilder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(rev)); + oldBuilder.add(StaticStrings::RevString, VPackValue(rev)); } oldBuilder.close(); @@ -1109,8 +1109,8 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, VPackSlice const r(reinterpret_cast(rhs)); VPackValueLength lLength, rLength; - char const* lKey = l.get(TRI_VOC_ATTRIBUTE_KEY).getString(lLength); - char const* rKey = r.get(TRI_VOC_ATTRIBUTE_KEY).getString(rLength); + char const* lKey = l.get(StaticStrings::KeyString).getString(lLength); + char const* rKey = r.get(StaticStrings::KeyString).getString(rLength); size_t const length = (lLength < rLength ? lLength : rLength); int res = memcmp(lKey, rKey, length); @@ -1219,7 +1219,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, for (size_t i = 0; i < markers.size(); ++i) { VPackSlice const k(reinterpret_cast(markers[i])); - std::string const key(k.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); + std::string const key(k.get(StaticStrings::KeyString).copyString()); if (key.compare(lowKey) >= 0) { break; @@ -1227,7 +1227,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, keyBuilder.clear(); keyBuilder.openObject(); - keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); + keyBuilder.add(StaticStrings::KeyString, VPackValue(key)); keyBuilder.close(); trx.remove(collectionName, keyBuilder.slice(), options); @@ -1245,7 +1245,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, for (size_t i = markers.size(); i >= 1; --i) { VPackSlice const k(reinterpret_cast(markers[i - 1])); - std::string const key(k.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); + std::string const key(k.get(StaticStrings::KeyString).copyString()); if (key.compare(highKey) <= 0) { break; @@ -1253,7 +1253,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, keyBuilder.clear(); keyBuilder.openObject(); - keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); + keyBuilder.add(StaticStrings::KeyString, VPackValue(key)); keyBuilder.close(); trx.remove(collectionName, keyBuilder.slice(), options); @@ -1329,8 +1329,8 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, for (size_t i = localFrom; i <= localTo; ++i) { TRI_ASSERT(i < markers.size()); VPackSlice const current(reinterpret_cast(markers.at(i))); - hash ^= current.get(TRI_VOC_ATTRIBUTE_KEY).hash(); - hash ^= current.get(TRI_VOC_ATTRIBUTE_REV).hash(); + hash ^= current.get(StaticStrings::KeyString).hash(); + hash ^= current.get(StaticStrings::RevString).hash(); } if (std::to_string(hash) != hashSlice.copyString()) { @@ -1397,13 +1397,13 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, // delete all keys at start of the range while (nextStart < markers.size()) { VPackSlice const keySlice(reinterpret_cast(markers[nextStart])); - std::string const localKey(keySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); + std::string const localKey(keySlice.get(StaticStrings::KeyString).copyString()); if (localKey.compare(lowString) < 0) { // we have a local key that is not present remotely keyBuilder.clear(); keyBuilder.openObject(); - keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(localKey)); + keyBuilder.add(StaticStrings::KeyString, VPackValue(localKey)); keyBuilder.close(); trx.remove(collectionName, keyBuilder.slice(), options); @@ -1451,7 +1451,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, while (nextStart < markers.size()) { VPackSlice const localKeySlice(reinterpret_cast(markers[nextStart])); - std::string const localKey(localKeySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); + std::string const localKey(localKeySlice.get(StaticStrings::KeyString).copyString()); int res = localKey.compare(keyString); @@ -1459,7 +1459,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, // we have a local key that is not present remotely keyBuilder.clear(); keyBuilder.openObject(); - keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(localKey)); + keyBuilder.add(StaticStrings::KeyString, VPackValue(localKey)); keyBuilder.close(); trx.remove(collectionName, keyBuilder.slice(), options); @@ -1491,7 +1491,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, while (nextStart < markers.size()) { VPackSlice const localKeySlice(reinterpret_cast(markers[nextStart])); - std::string const localKey(localKeySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); + std::string const localKey(localKeySlice.get(StaticStrings::KeyString).copyString()); int res = localKey.compare(highString); @@ -1573,7 +1573,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, return TRI_ERROR_REPLICATION_INVALID_RESPONSE; } - VPackSlice const keySlice = it.get(TRI_VOC_ATTRIBUTE_KEY); + VPackSlice const keySlice = it.get(StaticStrings::KeyString); if (!keySlice.isString()) { errorMsg = "got invalid response from master at " + @@ -1583,7 +1583,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col, return TRI_ERROR_REPLICATION_INVALID_RESPONSE; } - VPackSlice const revSlice = it.get(TRI_VOC_ATTRIBUTE_REV); + VPackSlice const revSlice = it.get(StaticStrings::RevString); if (!revSlice.isString()) { errorMsg = "got invalid response from master at " + diff --git a/arangod/RestHandler/RestBatchHandler.cpp b/arangod/RestHandler/RestBatchHandler.cpp index dd15409a50..5714540072 100644 --- a/arangod/RestHandler/RestBatchHandler.cpp +++ b/arangod/RestHandler/RestBatchHandler.cpp @@ -213,11 +213,8 @@ HttpHandler::status_t RestBatchHandler::execute() { _response->body().appendText(TRI_CHAR_LENGTH_PAIR("\r\n\r\n")); // remove some headers we don't need - static std::string const server = "server"; - static std::string const empty = ""; - partResponse->setConnectionType(HttpResponse::CONNECTION_NONE); - partResponse->setHeaderNC(server, empty); + partResponse->setHeaderNC(StaticStrings::Server, ""); // append the part response header partResponse->writeHeader(&_response->body()); diff --git a/arangod/RestServer/VocbaseContext.cpp b/arangod/RestServer/VocbaseContext.cpp index 4be92c9b3b..d6ca99aafa 100644 --- a/arangod/RestServer/VocbaseContext.cpp +++ b/arangod/RestServer/VocbaseContext.cpp @@ -174,10 +174,8 @@ bool VocbaseContext::useClusterAuthentication() const { //////////////////////////////////////////////////////////////////////////////// std::string VocbaseContext::realm() const { - static std::string EMPTY = ""; - if (_vocbase == nullptr) { - return EMPTY; + return std::string(""); } return _vocbase->_name; diff --git a/arangod/V8Server/v8-actions.cpp b/arangod/V8Server/v8-actions.cpp index 9c4a3064cd..2dee26e84d 100644 --- a/arangod/V8Server/v8-actions.cpp +++ b/arangod/V8Server/v8-actions.cpp @@ -543,20 +543,16 @@ static HttpResponse* ResponseV8ToCpp(v8::Isolate* isolate, std::string name = TRI_ObjectToString(transformator); // check available transformations - static std::string const contentEncoding = "content-encoding"; - if (name == "base64encode") { // base64-encode the result out = StringUtils::encodeBase64(out); // set the correct content-encoding header - static std::string const base64 = "base64"; - response->setHeaderNC(contentEncoding, base64); + response->setHeaderNC(StaticStrings::ContentEncoding, StaticStrings::Base64); } else if (name == "base64decode") { // base64-decode the result out = StringUtils::decodeBase64(out); // set the correct content-encoding header - static std::string const binary = "binary"; - response->setHeaderNC(contentEncoding, binary); + response->setHeaderNC(StaticStrings::ContentEncoding, StaticStrings::Binary); } } diff --git a/arangod/V8Server/v8-util.cpp b/arangod/V8Server/v8-util.cpp index cf158887fd..a94bf362c5 100644 --- a/arangod/V8Server/v8-util.cpp +++ b/arangod/V8Server/v8-util.cpp @@ -190,7 +190,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate, if (key.get() == nullptr) { return false; } - builder.add(TRI_VOC_ATTRIBUTE_KEY, + builder.add(StaticStrings::KeyString, VPackValue(reinterpret_cast(key.get()))); } return res; @@ -223,7 +223,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate, return false; } // If we get here we have a valid key - builder.add(TRI_VOC_ATTRIBUTE_KEY, + builder.add(StaticStrings::KeyString, VPackValue(reinterpret_cast(key.get()))); if (!includeRev) { @@ -241,7 +241,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate, if (rid == 0) { return false; } - builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(std::to_string(rid))); + builder.add(StaticStrings::RevString, VPackValue(std::to_string(rid))); return true; } diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 2bc2396e80..2c75fb2328 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -156,7 +156,7 @@ static int ProcessIndexFields(v8::Isolate* isolate, std::string const f = TRI_ObjectToString(fieldList->Get(i)); - if (f.empty() || (create && f == TRI_VOC_ATTRIBUTE_ID)) { + if (f.empty() || (create && f == StaticStrings::IdString)) { // accessing internal attributes is disallowed return TRI_ERROR_BAD_PARAMETER; } diff --git a/arangosh/Benchmark/BenchmarkThread.h b/arangosh/Benchmark/BenchmarkThread.h index fd49301d93..cb8e2c569c 100644 --- a/arangosh/Benchmark/BenchmarkThread.h +++ b/arangosh/Benchmark/BenchmarkThread.h @@ -173,16 +173,15 @@ class BenchmarkThread : public arangodb::Thread { TRI_ASSERT(t != nullptr); - if (location.substr(0, 5) == "/_db/") { + if (location.compare(0, 5, "/_db/") == 0) { // location already contains /_db/ return location; } if (location[0] == '/') { return std::string("/_db/" + t->_databaseName + location); - } else { - return std::string("/_db/" + t->_databaseName + "/" + location); - } + } + return std::string("/_db/" + t->_databaseName + "/" + location); } ////////////////////////////////////////////////////////////////////////////// @@ -248,7 +247,6 @@ class BenchmarkThread : public arangodb::Thread { batchPayload.appendText(boundary, blen); batchPayload.appendText(TRI_CHAR_LENGTH_PAIR("--\r\n")); - _headers.erase("Content-Type"); _headers["Content-Type"] = HttpRequest::MULTI_PART_CONTENT_TYPE + "; boundary=" + boundary; diff --git a/arangosh/V8Client/ArangoClientHelper.cpp b/arangosh/V8Client/ArangoClientHelper.cpp index 4414a87a9c..fe80b0704b 100644 --- a/arangosh/V8Client/ArangoClientHelper.cpp +++ b/arangosh/V8Client/ArangoClientHelper.cpp @@ -41,7 +41,7 @@ ArangoClientHelper::ArangoClientHelper() : _httpClient(nullptr) {} // helper to rewrite HTTP location std::string ArangoClientHelper::rewriteLocation(void* data, std::string const& location) { - if (location.substr(0, 5) == "/_db/") { + if (location.compare(0, 5, "/_db/") == 0) { return location; } diff --git a/lib/Basics/StaticStrings.cpp b/lib/Basics/StaticStrings.cpp index 910796e9e2..124aa0d32a 100644 --- a/lib/Basics/StaticStrings.cpp +++ b/lib/Basics/StaticStrings.cpp @@ -25,6 +25,8 @@ using namespace arangodb; // constants +std::string const StaticStrings::Base64("base64"); +std::string const StaticStrings::Binary("binary"); std::string const StaticStrings::N1800("1800"); // system attribute names @@ -51,8 +53,10 @@ std::string const StaticStrings::Allow("allow"); std::string const StaticStrings::Async("x-arango-async"); std::string const StaticStrings::AsyncId("x-arango-async-id"); std::string const StaticStrings::Authorization("authorization"); +std::string const StaticStrings::CacheControl("cache-control"); std::string const StaticStrings::Close("Close"); std::string const StaticStrings::Connection("connection"); +std::string const StaticStrings::ContentEncoding("content-encoding"); std::string const StaticStrings::ContentTypeHeader("content-type"); std::string const StaticStrings::Coordinator("x-arango-coordinator"); std::string const StaticStrings::CorsMethods("DELETE, GET, HEAD, PATCH, POST, PUT"); diff --git a/lib/Basics/StaticStrings.h b/lib/Basics/StaticStrings.h index 58977be195..af2e43e3f0 100644 --- a/lib/Basics/StaticStrings.h +++ b/lib/Basics/StaticStrings.h @@ -31,6 +31,8 @@ class StaticStrings { public: // constants + static std::string const Base64; + static std::string const Binary; static std::string const N1800; // system attribute names @@ -57,8 +59,10 @@ class StaticStrings { static std::string const Async; static std::string const AsyncId; static std::string const Authorization; + static std::string const CacheControl; static std::string const Close; static std::string const Connection; + static std::string const ContentEncoding; static std::string const ContentTypeHeader; static std::string const Coordinator; static std::string const CorsMethods;