1
0
Fork 0

use unique_ptr

This commit is contained in:
Jan Steemann 2015-08-06 22:13:33 +02:00 committed by Michael Hackstein
parent 907e6368c6
commit ba84a982b6
3 changed files with 19 additions and 17 deletions

View File

@ -162,7 +162,7 @@ RestEdgeHandler::RestEdgeHandler (HttpRequest* request)
bool RestEdgeHandler::createDocument () {
vector<string> const& suffix = _request->suffix();
if (suffix.size() != 0) {
if (! suffix.empty()) {
generateError(HttpResponse::BAD,
TRI_ERROR_HTTP_SUPERFLUOUS_SUFFICES,
"superfluous suffix, expecting " + EDGE_PATH + "?collection=<identifier>");

View File

@ -49,7 +49,7 @@ static bool IsReflexive (TRI_doc_mptr_t const* mptr) {
TRI_df_marker_t const* marker = static_cast<TRI_df_marker_t const*>(mptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
if (marker->_type == TRI_DOC_MARKER_KEY_EDGE) {
TRI_doc_edge_key_marker_t const* edge = static_cast<TRI_doc_edge_key_marker_t const*>(mptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
auto const* edge = reinterpret_cast<TRI_doc_edge_key_marker_t const*>(marker); // ONLY IN INDEX, PROTECTED by RUNTIME
if (edge->_toCid == edge->_fromCid) {
char const* fromKey = reinterpret_cast<char const*>(edge) + edge->_offsetFromKey;
@ -59,7 +59,7 @@ static bool IsReflexive (TRI_doc_mptr_t const* mptr) {
}
}
else if (marker->_type == TRI_WAL_MARKER_EDGE) {
triagens::wal::edge_marker_t const* edge = static_cast<triagens::wal::edge_marker_t const*>(mptr->getDataPtr()); // ONLY IN INDEX, PROTECTED by RUNTIME
auto const* edge = reinterpret_cast<triagens::wal::edge_marker_t const*>(marker); // ONLY IN INDEX, PROTECTED by RUNTIME
if (edge->_toCid == edge->_fromCid) {
char const* fromKey = reinterpret_cast<char const*>(edge) + edge->_offsetFromKey;
@ -83,15 +83,15 @@ static bool IsReflexive (TRI_doc_mptr_t const* mptr) {
static bool FindEdges (TRI_edge_direction_e direction,
triagens::arango::EdgeIndex* edgeIndex,
std::vector<TRI_doc_mptr_copy_t>& result,
TRI_edge_header_t* entry,
TRI_edge_header_t const* entry,
int matchType) {
std::vector<void*>* found = nullptr;
std::unique_ptr<std::vector<void*>> found;
if (direction == TRI_EDGE_OUT) {
found = edgeIndex->from()->lookupByKey(static_cast<void*>(entry));
found.reset(edgeIndex->from()->lookupByKey(static_cast<void const*>(entry)));
}
else if (direction == TRI_EDGE_IN) {
found = edgeIndex->to()->lookupByKey(static_cast<void*>(entry));
found.reset(edgeIndex->to()->lookupByKey(static_cast<void const*>(entry)));
}
else {
TRI_ASSERT(false); // TRI_EDGE_ANY not supported here
@ -130,12 +130,9 @@ static bool FindEdges (TRI_edge_direction_e direction,
}
result.emplace_back(*edge);
}
}
delete found;
return true;
}
@ -153,9 +150,7 @@ std::vector<TRI_doc_mptr_copy_t> TRI_LookupEdgesDocumentCollection (
TRI_voc_cid_t cid,
TRI_voc_key_t const key) {
// search criteria
TRI_edge_header_t entry;
entry._cid = cid;
entry._key = key;
TRI_edge_header_t entry(cid, key);
// initialise the result vector
std::vector<TRI_doc_mptr_copy_t> result;

View File

@ -58,11 +58,16 @@ TRI_edge_direction_e;
/// @brief index entry for edges
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_edge_header_s {
struct TRI_edge_header_t {
TRI_edge_header_t (TRI_voc_cid_t cid,
TRI_voc_key_t key)
: _cid(cid),
_key(key) {
}
TRI_voc_cid_t _cid; // from or to, depending on the direction
TRI_voc_key_t _key;
}
TRI_edge_header_t;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief edge index iterator
@ -73,10 +78,12 @@ struct TRI_edge_index_iterator_t {
TRI_voc_cid_t cid,
TRI_voc_key_t key)
: _direction(direction),
_edge({ cid, nullptr }) {
_edge(cid, nullptr) {
TRI_ASSERT(key != nullptr);
_edge._key = TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, key);
if (_edge._key == nullptr) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
}