diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp index a6a390e1..cca76694 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp @@ -23,10 +23,11 @@ SharedIntermediateStorage::~SharedIntermediateStorage() std::vector SharedIntermediateStorage::getStorageFiles() const { std::vector result; + result.reserve(m_storageFiles.size()); for (unsigned int i = 0; i < m_storageFiles.size(); i++) { - result.push_back(fromShared(m_storageFiles[i])); + result.emplace_back(fromShared(m_storageFiles[i])); } return result; @@ -45,10 +46,11 @@ void SharedIntermediateStorage::setStorageFiles(const std::vector& std::vector SharedIntermediateStorage::getStorageNodes() const { std::vector result; + result.reserve(m_storageNodes.size()); for (unsigned int i = 0; i < m_storageNodes.size(); i++) { - result.push_back(fromShared(m_storageNodes[i])); + result.emplace_back(fromShared(m_storageNodes[i])); } return result; @@ -67,10 +69,11 @@ void SharedIntermediateStorage::setStorageNodes(const std::vector& std::vector SharedIntermediateStorage::getStorageSymbols() const { std::vector result; + result.reserve(m_storageSymbols.size()); for (unsigned int i = 0; i < m_storageSymbols.size(); i++) { - result.push_back(fromShared(m_storageSymbols[i])); + result.emplace_back(fromShared(m_storageSymbols[i])); } return result; @@ -89,10 +92,11 @@ void SharedIntermediateStorage::setStorageSymbols(const std::vector SharedIntermediateStorage::getStorageEdges() const { std::vector result; + result.reserve(m_storageEdges.size()); for (unsigned int i = 0; i < m_storageEdges.size(); i++) { - result.push_back(fromShared(m_storageEdges[i])); + result.emplace_back(fromShared(m_storageEdges[i])); } return result; @@ -108,123 +112,124 @@ void SharedIntermediateStorage::setStorageEdges(const std::vector& } } -std::vector SharedIntermediateStorage::getStorageLocalSymbols() const +std::set SharedIntermediateStorage::getStorageLocalSymbols() const { - std::vector result; + std::set result; for (unsigned int i = 0; i < m_storageLocalSymbols.size(); i++) { - result.push_back(fromShared(m_storageLocalSymbols[i])); + result.emplace(fromShared(m_storageLocalSymbols[i])); } return result; } -void SharedIntermediateStorage::setStorageLocalSymbols(const std::vector& storageLocalSymbols) +void SharedIntermediateStorage::setStorageLocalSymbols(const std::set& storageLocalSymbols) { m_storageLocalSymbols.clear(); - for (unsigned int i = 0; i < storageLocalSymbols.size(); i++) + for (const StorageLocalSymbol& localSymbol : storageLocalSymbols) { - m_storageLocalSymbols.push_back(toShared(storageLocalSymbols[i], m_allocator)); + m_storageLocalSymbols.push_back(toShared(localSymbol, m_allocator)); } } -std::vector SharedIntermediateStorage::getStorageSourceLocations() const +std::set SharedIntermediateStorage::getStorageSourceLocations() const { - std::vector result; + std::set result; for (unsigned int i = 0; i < m_storageSourceLocations.size(); i++) { - result.push_back(fromShared(m_storageSourceLocations[i])); + result.emplace(fromShared(m_storageSourceLocations[i])); } return result; } -void SharedIntermediateStorage::setStorageSourceLocations(const std::vector& storageSourceLocations) +void SharedIntermediateStorage::setStorageSourceLocations(const std::set& storageSourceLocations) { m_storageSourceLocations.clear(); - for (unsigned int i = 0; i < storageSourceLocations.size(); i++) + for (const StorageSourceLocation& sourceLocation : storageSourceLocations) { - m_storageSourceLocations.push_back(toShared(storageSourceLocations[i], m_allocator)); + m_storageSourceLocations.push_back(toShared(sourceLocation, m_allocator)); } } -std::vector SharedIntermediateStorage::getStorageOccurrences() const +std::set SharedIntermediateStorage::getStorageOccurrences() const { - std::vector result; + std::set result; for (unsigned int i = 0; i < m_storageOccurrences.size(); i++) { - result.push_back(fromShared(m_storageOccurrences[i])); + result.emplace(fromShared(m_storageOccurrences[i])); } return result; } -void SharedIntermediateStorage::setStorageOccurrences(const std::vector& storageOccurences) +void SharedIntermediateStorage::setStorageOccurrences(const std::set& storageOccurences) { m_storageOccurrences.clear(); - for (unsigned int i = 0; i < storageOccurences.size(); i++) + for (const StorageOccurrence& occurrence : storageOccurences) { - m_storageOccurrences.push_back(toShared(storageOccurences[i], m_allocator)); + m_storageOccurrences.push_back(toShared(occurrence, m_allocator)); } } -std::vector SharedIntermediateStorage::getStorageComponentAccesses() const +std::set SharedIntermediateStorage::getStorageComponentAccesses() const { - std::vector result; + std::set result; for (unsigned int i = 0; i < m_storageComponentAccesses.size(); i++) { - result.push_back(fromShared(m_storageComponentAccesses[i])); + result.emplace(fromShared(m_storageComponentAccesses[i])); } return result; } -void SharedIntermediateStorage::setStorageComponentAccesses(const std::vector& storageComponentAccesses) +void SharedIntermediateStorage::setStorageComponentAccesses(const std::set& storageComponentAccesses) { m_storageComponentAccesses.clear(); - for (unsigned int i = 0; i < storageComponentAccesses.size(); i++) + for (const StorageComponentAccess& componentAccess : storageComponentAccesses) { - m_storageComponentAccesses.push_back(toShared(storageComponentAccesses[i], m_allocator)); + m_storageComponentAccesses.push_back(toShared(componentAccess, m_allocator)); } } -std::vector SharedIntermediateStorage::getStorageCommentLocations() const +std::set SharedIntermediateStorage::getStorageCommentLocations() const { - std::vector result; + std::set result; for (unsigned int i = 0; i < m_storageCommentLocations.size(); i++) { - result.push_back(fromShared(m_storageCommentLocations[i])); + result.emplace(fromShared(m_storageCommentLocations[i])); } return result; } -void SharedIntermediateStorage::setStorageCommentLocations(const std::vector& commentLocations) +void SharedIntermediateStorage::setStorageCommentLocations(const std::set& commentLocations) { m_storageCommentLocations.clear(); - for (unsigned int i = 0; i < commentLocations.size(); i++) + for (const StorageCommentLocationData commentLocation : commentLocations) { - m_storageCommentLocations.push_back(toShared(commentLocations[i], m_allocator)); + m_storageCommentLocations.push_back(toShared(commentLocation, m_allocator)); } } std::vector SharedIntermediateStorage::getStorageErrors() const { std::vector result; + result.reserve(m_storageErrors.size()); for (unsigned int i = 0; i < m_storageErrors.size(); i++) { - result.push_back(fromShared(m_storageErrors[i])); + result.emplace_back(fromShared(m_storageErrors[i])); } return result; diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h index 4907a8a5..9f059de3 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h @@ -22,20 +22,20 @@ public: std::vector getStorageEdges() const; void setStorageEdges(const std::vector& storageEdges); - std::vector getStorageLocalSymbols() const; - void setStorageLocalSymbols(const std::vector& storageLocalSymbols); + std::set getStorageLocalSymbols() const; + void setStorageLocalSymbols(const std::set& storageLocalSymbols); - std::vector getStorageSourceLocations() const; - void setStorageSourceLocations(const std::vector& storageSourceLocations); + std::set getStorageSourceLocations() const; + void setStorageSourceLocations(const std::set& storageSourceLocations); - std::vector getStorageOccurrences() const; - void setStorageOccurrences(const std::vector& storageOccurences); + std::set getStorageOccurrences() const; + void setStorageOccurrences(const std::set& storageOccurences); - std::vector getStorageComponentAccesses() const; - void setStorageComponentAccesses(const std::vector& storageComponentAccesses); + std::set getStorageComponentAccesses() const; + void setStorageComponentAccesses(const std::set& storageComponentAccesses); - std::vector getStorageCommentLocations() const; - void setStorageCommentLocations(const std::vector& commentLocations); + std::set getStorageCommentLocations() const; + void setStorageCommentLocations(const std::set& commentLocations); std::vector getStorageErrors() const; void setStorageErrors(const std::vector& errors); diff --git a/src/lib/data/storage/IntermediateStorage.cpp b/src/lib/data/storage/IntermediateStorage.cpp index dfb2f4f4..8a30984c 100644 --- a/src/lib/data/storage/IntermediateStorage.cpp +++ b/src/lib/data/storage/IntermediateStorage.cpp @@ -1,6 +1,6 @@ #include "data/storage/IntermediateStorage.h" -#include +#include "utility/utility.h" IntermediateStorage::IntermediateStorage() : m_nextId(1) @@ -9,18 +9,26 @@ IntermediateStorage::IntermediateStorage() void IntermediateStorage::clear() { - m_nodes.clear(); m_nodesIndex.clear(); + m_nodes.clear(); + + m_filesIndex.clear(); m_files.clear(); + m_symbols.clear(); - m_edges.clear(); + m_edgesIndex.clear(); + m_edges.clear(); + m_localSymbols.clear(); m_sourceLocations.clear(); m_occurrences.clear(); m_componentAccesses.clear(); m_commentLocations.clear(); + + m_errorsIndex.clear(); m_errors.clear(); + m_nextId = 1; } @@ -96,8 +104,7 @@ void IntermediateStorage::setFilesWithErrorsIncomplete() Id IntermediateStorage::addNode(const StorageNodeData& nodeData) { - const std::wstring serialized = serialize(nodeData); - std::unordered_map::iterator it = m_nodesIndex.find(serialized); + auto it = m_nodesIndex.find(nodeData); if (it != m_nodesIndex.end()) { StorageNode& storedNode = m_nodes[it->second]; @@ -108,10 +115,10 @@ Id IntermediateStorage::addNode(const StorageNodeData& nodeData) return storedNode.id; } - const StorageNode node(m_nextId++, nodeData); - m_nodes.push_back(node); - m_nodesIndex.emplace(serialized, m_nodes.size() - 1); - return node.id; + Id nodeId = m_nextId++; + m_nodes.emplace_back(nodeId, nodeData); + m_nodesIndex.emplace(nodeData, m_nodes.size() - 1); + return nodeId; } void IntermediateStorage::addSymbol(const StorageSymbol& symbol) @@ -121,13 +128,11 @@ void IntermediateStorage::addSymbol(const StorageSymbol& symbol) void IntermediateStorage::addFile(const StorageFile& file) { - const std::wstring serialized = serialize(file); - - std::unordered_map::const_iterator it = m_serializedFiles.find(serialized); - if (it == m_serializedFiles.end()) + auto it = m_filesIndex.find(file); + if (it == m_filesIndex.end()) { - m_serializedFiles.emplace(serialized, m_files.size()); - m_files.push_back(file); + m_filesIndex.emplace(file, m_files.size()); + m_files.emplace_back(file); } else { @@ -147,97 +152,70 @@ void IntermediateStorage::addFile(const StorageFile& file) Id IntermediateStorage::addEdge(const StorageEdgeData& edgeData) { - const std::wstring serialized = serialize(edgeData); - std::unordered_map::const_iterator it = m_edgesIndex.find(serialized); + auto it = m_edgesIndex.find(edgeData); if (it != m_edgesIndex.end()) { return m_edges[it->second].id; } - const StorageEdge edge = StorageEdge(m_nextId++, edgeData); - m_edges.push_back(edge); - m_edgesIndex.emplace(serialized, m_edges.size() - 1); - return edge.id; + Id edgeId = m_nextId++; + m_edges.emplace_back(edgeId, edgeData); + m_edgesIndex.emplace(edgeData, m_edges.size() - 1); + return edgeId; } Id IntermediateStorage::addLocalSymbol(const StorageLocalSymbolData& localSymbolData) { - - const std::wstring serialized = serialize(localSymbolData); - std::unordered_map::const_iterator it = m_localSymbols.find(serialized); + auto it = m_localSymbols.find(StorageLocalSymbol(0, localSymbolData)); if (it != m_localSymbols.end()) { - return it->second.id; + return it->id; } - const StorageLocalSymbol localSymbol = StorageLocalSymbol(m_nextId++, localSymbolData); - m_localSymbols[serialized] = localSymbol; - return localSymbol.id; + Id localSymbolId = m_nextId++; + m_localSymbols.emplace(localSymbolId, localSymbolData); + return localSymbolId; } Id IntermediateStorage::addSourceLocation(const StorageSourceLocationData& sourceLocationData) { - const std::wstring serialized = serialize(sourceLocationData); - std::unordered_map::const_iterator it = m_sourceLocations.find(serialized); + auto it = m_sourceLocations.find(StorageSourceLocation(0, sourceLocationData)); if (it != m_sourceLocations.end()) { - return it->second.id; + return it->id; } - const StorageSourceLocation sourceLocation = StorageSourceLocation(m_nextId++, sourceLocationData); - m_sourceLocations[serialized] = sourceLocation; - return sourceLocation.id; + Id sourceLocationId = m_nextId++; + m_sourceLocations.emplace(sourceLocationId, sourceLocationData); + return sourceLocationId; } void IntermediateStorage::addOccurrence(const StorageOccurrence& occurrence) { - const std::wstring serialized = serialize(occurrence); - - if (m_serializedOccurrences.find(serialized) == m_serializedOccurrences.end()) - { - m_occurrences.push_back(occurrence); - m_serializedOccurrences.insert(serialized); - } + m_occurrences.emplace(occurrence); } void IntermediateStorage::addOccurrences(const std::vector& occurrences) { - for (const StorageOccurrence& occurrence : occurrences) - { - addOccurrence(occurrence); - } + m_occurrences.insert(occurrences.begin(), occurrences.end()); } void IntermediateStorage::addComponentAccess(const StorageComponentAccess& componentAccess) { - const std::wstring serialized = serialize(componentAccess); - - if (m_serializedComponentAccesses.find(serialized) == m_serializedComponentAccesses.end()) - { - m_componentAccesses.push_back(componentAccess); - m_serializedComponentAccesses.insert(serialized); - } + m_componentAccesses.emplace(componentAccess); } void IntermediateStorage::addCommentLocation(const StorageCommentLocationData& commentLocationData) { - const std::wstring serialized = serialize(commentLocationData); - - if (m_serializedCommentLocations.find(serialized) == m_serializedCommentLocations.end()) - { - m_commentLocations.push_back(commentLocationData); - m_serializedCommentLocations.insert(serialized); - } + m_commentLocations.emplace(commentLocationData); } void IntermediateStorage::addError(const StorageErrorData& errorData) { - const std::wstring serialized = serialize(errorData); - - if (m_serializedErrors.find(serialized) == m_serializedErrors.end()) + if (m_errorsIndex.find(errorData) == m_errorsIndex.end()) { - m_errors.push_back(errorData); - m_serializedErrors.insert(serialized); + m_errors.emplace_back(errorData); + m_errorsIndex.emplace(errorData); } } @@ -251,17 +229,17 @@ void IntermediateStorage::forEachNode(std::function callback) const { - for (std::vector::const_iterator it = m_files.begin(); it != m_files.end(); it++) + for (const StorageFile& file : m_files) { - callback(*it); + callback(file); } } void IntermediateStorage::forEachSymbol(std::function callback) const { - for (std::vector::const_iterator it = m_symbols.begin(); it != m_symbols.end(); it++) + for (const StorageSymbol& symbol : m_symbols) { - callback(*it); + callback(symbol); } } @@ -275,51 +253,49 @@ void IntermediateStorage::forEachEdge(std::function callback) const { - for (std::unordered_map::const_iterator it = m_localSymbols.begin(); - it != m_localSymbols.end(); it++) + for (const StorageLocalSymbol& localSymbol : m_localSymbols) { - callback(it->second); + callback(localSymbol); } } void IntermediateStorage::forEachSourceLocation(std::function callback) const { - for (std::unordered_map::const_iterator it = m_sourceLocations.begin(); - it != m_sourceLocations.end(); it++) + for (const StorageSourceLocation& sourceLocation : m_sourceLocations) { - callback(it->second); + callback(sourceLocation); } } void IntermediateStorage::forEachOccurrence(std::function callback) const { - for (std::vector::const_iterator it = m_occurrences.begin(); it != m_occurrences.end(); it++) + for (const StorageOccurrence& occurrence : m_occurrences) { - callback(*it); + callback(occurrence); } } void IntermediateStorage::forEachComponentAccess(std::function callback) const { - for (std::vector::const_iterator it = m_componentAccesses.begin(); it != m_componentAccesses.end(); it++) + for (const StorageComponentAccess& componentAccess : m_componentAccesses) { - callback(*it); + callback(componentAccess); } } void IntermediateStorage::forEachCommentLocation(std::function callback) const { - for (std::vector::const_iterator it = m_commentLocations.begin(); it != m_commentLocations.end(); it++) + for (const StorageCommentLocationData& commentLocation : m_commentLocations) { - callback(*it); + callback(commentLocation); } } void IntermediateStorage::forEachError(std::function callback) const { - for (std::vector::const_iterator it = m_errors.begin(); it != m_errors.end(); it++) + for (const StorageErrorData& error : m_errors) { - callback(*it); + callback(error); } } @@ -343,39 +319,27 @@ const std::vector& IntermediateStorage::getStorageEdges() const return m_edges; } -std::vector IntermediateStorage::getStorageLocalSymbols() const +const std::set& IntermediateStorage::getStorageLocalSymbols() const { - std::vector localSymbol; - localSymbol.reserve(m_localSymbols.size()); - for (const auto& it: m_localSymbols) - { - localSymbol.push_back(it.second); - } - return localSymbol; + return m_localSymbols; } -std::vector IntermediateStorage::getStorageSourceLocations() const +const std::set& IntermediateStorage::getStorageSourceLocations() const { - std::vector sourceLocations; - sourceLocations.reserve(m_sourceLocations.size()); - for (const auto& it: m_sourceLocations) - { - sourceLocations.push_back(it.second); - } - return sourceLocations; + return m_sourceLocations; } -const std::vector& IntermediateStorage::getStorageOccurrences() const +const std::set& IntermediateStorage::getStorageOccurrences() const { return m_occurrences; } -const std::vector& IntermediateStorage::getComponentAccesses() const +const std::set& IntermediateStorage::getComponentAccesses() const { return m_componentAccesses; } -const std::vector& IntermediateStorage::getCommentLocations() const +const std::set& IntermediateStorage::getCommentLocations() const { return m_commentLocations; } @@ -385,74 +349,73 @@ const std::vector& IntermediateStorage::getErrors() const return m_errors; } -void IntermediateStorage::setStorageNodes(const std::vector& storageNodes) +void IntermediateStorage::setStorageNodes(std::vector storageNodes) { - m_nodes.clear(); + m_nodes = std::move(storageNodes); + m_nodesIndex.clear(); - for (const StorageNode& storageNode: storageNodes) + for (size_t i = 0; i < m_nodes.size(); i++) { - m_nodes.push_back(storageNode); - m_nodesIndex.emplace(serialize(storageNode), m_nodes.size() - 1); + m_nodesIndex.emplace(m_nodes[i], i); } } -void IntermediateStorage::setStorageFiles(const std::vector& storageFiles) +void IntermediateStorage::setStorageFiles(std::vector storageFiles) { - m_files = storageFiles; + m_files = std::move(storageFiles); + + m_filesIndex.clear(); + for (size_t i = 0; i < m_files.size(); i++) + { + m_filesIndex.emplace(m_files[i], i); + } } -void IntermediateStorage::setStorageSymbols(const std::vector& storageSymbols) +void IntermediateStorage::setStorageSymbols(std::vector storageSymbols) { - m_symbols = storageSymbols; + m_symbols = std::move(storageSymbols); } -void IntermediateStorage::setStorageEdges(const std::vector& storageEdges) +void IntermediateStorage::setStorageEdges(std::vector storageEdges) { - m_edges.clear(); + m_edges = std::move(storageEdges); + m_edgesIndex.clear(); - for (const StorageEdge& storageEdge: storageEdges) + for (size_t i = 0; i < m_edges.size(); i++) { - m_edges.push_back(storageEdge); - m_edgesIndex.emplace(serialize(storageEdge), m_edges.size() - 1); + m_edgesIndex.emplace(m_edges[i], i); } } -void IntermediateStorage::setStorageLocalSymbols(const std::vector& storageLocalSymbols) +void IntermediateStorage::setStorageLocalSymbols(std::set storageLocalSymbols) { - m_localSymbols.clear(); - for (const StorageLocalSymbol& storageLocalSymbol: storageLocalSymbols) - { - m_localSymbols[serialize(storageLocalSymbol)] = storageLocalSymbol; - } + m_localSymbols = std::move(storageLocalSymbols); } -void IntermediateStorage::setStorageSourceLocations(const std::vector& storageSourceLocations) +void IntermediateStorage::setStorageSourceLocations(std::set storageSourceLocations) { - m_sourceLocations.clear(); - for (const StorageSourceLocation& storageSourceLocation: storageSourceLocations) - { - m_sourceLocations[serialize(storageSourceLocation)] = storageSourceLocation; - } + m_sourceLocations = std::move(storageSourceLocations); } -void IntermediateStorage::setStorageOccurrences(const std::vector& storageOccurrences) +void IntermediateStorage::setStorageOccurrences(std::set storageOccurrences) { - m_occurrences = storageOccurrences; + m_occurrences = std::move(storageOccurrences); } -void IntermediateStorage::setComponentAccesses(const std::vector& componentAccesses) +void IntermediateStorage::setComponentAccesses(std::set componentAccesses) { - m_componentAccesses = componentAccesses; + m_componentAccesses = std::move(componentAccesses); } -void IntermediateStorage::setCommentLocations(const std::vector& commentLocations) +void IntermediateStorage::setCommentLocations(std::set commentLocations) { - m_commentLocations = commentLocations; + m_commentLocations = std::move(commentLocations); } -void IntermediateStorage::setErrors(const std::vector& errors) +void IntermediateStorage::setErrors(std::vector errors) { - m_errors = errors; + m_errors = std::move(errors); + m_errorsIndex = utility::toSet(m_errors); } Id IntermediateStorage::getNextId() const @@ -464,74 +427,3 @@ void IntermediateStorage::setNextId(const Id nextId) { m_nextId = nextId; } - -std::wstring IntermediateStorage::serialize(const StorageNodeData& nodeData) const -{ - return nodeData.serializedName; -} - -std::wstring IntermediateStorage::serialize(const StorageFile& file) const -{ - return file.filePath; -} - -std::wstring IntermediateStorage::serialize(const StorageEdgeData& edgeData) const -{ - return ( - std::to_wstring(edgeData.type) + L";" + - std::to_wstring(edgeData.sourceNodeId) + L";" + - std::to_wstring(edgeData.targetNodeId) - ); -} - -std::wstring IntermediateStorage::serialize(const StorageLocalSymbolData& localSymbolData) const -{ - return localSymbolData.name; -} - -std::wstring IntermediateStorage::serialize(const StorageSourceLocationData& sourceLocationData) const -{ - return ( - std::to_wstring(sourceLocationData.fileNodeId) + L";" + - std::to_wstring(sourceLocationData.startLine) + L";" + - std::to_wstring(sourceLocationData.startCol) + L";" + - std::to_wstring(sourceLocationData.endLine) + L";" + - std::to_wstring(sourceLocationData.endCol) + L";" + - std::to_wstring(sourceLocationData.type) - ); -} - -std::wstring IntermediateStorage::serialize(const StorageOccurrence& occurrence) const -{ - return std::to_wstring(occurrence.elementId) + L";" + std::to_wstring(occurrence.sourceLocationId); -} - - -std::wstring IntermediateStorage::serialize(const StorageComponentAccess& componentAccessData) const -{ - return std::to_wstring(componentAccessData.nodeId); -} - - -std::wstring IntermediateStorage::serialize(const StorageCommentLocationData& commentLocationData) const -{ - return ( - std::to_wstring(commentLocationData.fileNodeId) + L";" + - std::to_wstring(commentLocationData.startLine) + L";" + - std::to_wstring(commentLocationData.startCol) + L";" + - std::to_wstring(commentLocationData.endLine) + L";" + - std::to_wstring(commentLocationData.endCol) - ); -} - - -std::wstring IntermediateStorage::serialize(const StorageErrorData& errorData) const -{ - return ( - errorData.message + L";" + - std::to_wstring(errorData.fatal) + L";" + - errorData.filePath + L";" + - std::to_wstring(errorData.lineNumber) + L";" + - std::to_wstring(errorData.columnNumber) - ); -} diff --git a/src/lib/data/storage/IntermediateStorage.h b/src/lib/data/storage/IntermediateStorage.h index 6bf030e5..1683b5b6 100644 --- a/src/lib/data/storage/IntermediateStorage.h +++ b/src/lib/data/storage/IntermediateStorage.h @@ -3,8 +3,7 @@ #include #include -#include -#include +#include #include "data/storage/type/StorageCommentLocation.h" #include "data/storage/type/StorageComponentAccess.h" @@ -60,63 +59,52 @@ public: const std::vector& getStorageFiles() const; const std::vector& getStorageSymbols() const; const std::vector& getStorageEdges() const; - std::vector getStorageLocalSymbols() const; - std::vector getStorageSourceLocations() const; - const std::vector& getStorageOccurrences() const; - const std::vector& getComponentAccesses() const; - const std::vector& getCommentLocations() const; + const std::set& getStorageLocalSymbols() const; + const std::set& getStorageSourceLocations() const; + const std::set& getStorageOccurrences() const; + const std::set& getComponentAccesses() const; + const std::set& getCommentLocations() const; const std::vector& getErrors() const; - void setStorageNodes(const std::vector& storageNodes); - void setStorageFiles(const std::vector& storageFiles); - void setStorageSymbols(const std::vector& storageSymbols); - void setStorageEdges(const std::vector& storageEdges); - void setStorageLocalSymbols(const std::vector& storageLocalSymbols); - void setStorageSourceLocations(const std::vector& storageSourceLocations); - void setStorageOccurrences(const std::vector& storageOccurrences); - void setComponentAccesses(const std::vector& componentAccesses); - void setCommentLocations(const std::vector& commentLocations); - void setErrors(const std::vector& errors); + void setStorageNodes(std::vector storageNodes); + void setStorageFiles(std::vector storageFiles); + void setStorageSymbols(std::vector storageSymbols); + void setStorageEdges(std::vector storageEdges); + void setStorageLocalSymbols(std::set storageLocalSymbols); + void setStorageSourceLocations(std::set storageSourceLocations); + void setStorageOccurrences(std::set storageOccurrences); + void setComponentAccesses(std::set componentAccesses); + void setCommentLocations(std::set commentLocations); + void setErrors(std::vector errors); Id getNextId() const; void setNextId(const Id nextId); private: - std::wstring serialize(const StorageNodeData& nodeData) const; - std::wstring serialize(const StorageFile& file) const; - std::wstring serialize(const StorageEdgeData& edgeData) const; - std::wstring serialize(const StorageLocalSymbolData& localSymbolData) const; - std::wstring serialize(const StorageSourceLocationData& sourceLocationData) const; - std::wstring serialize(const StorageOccurrence& occurrence) const; - std::wstring serialize(const StorageComponentAccess& componentAccessData) const; - std::wstring serialize(const StorageCommentLocationData& commentLocationData) const; std::wstring serialize(const StorageErrorData& errorData) const; - std::unordered_map m_nodesIndex; + std::map m_nodesIndex; std::vector m_nodes; - std::unordered_map m_serializedFiles; // this is used to prevent duplicates (unique) + std::map m_filesIndex; // this is used to prevent duplicates (unique) std::vector m_files; std::vector m_symbols; - std::unordered_map m_edgesIndex; + std::map m_edgesIndex; std::vector m_edges; - std::unordered_map m_localSymbols; + std::set m_localSymbols; - std::unordered_map m_sourceLocations; + std::set m_sourceLocations; - std::unordered_set m_serializedOccurrences; // this is used to prevent duplicates (unique) - std::vector m_occurrences; + std::set m_occurrences; - std::unordered_set m_serializedComponentAccesses; // this is used to prevent duplicates (unique) - std::vector m_componentAccesses; + std::set m_componentAccesses; - std::unordered_set m_serializedCommentLocations; // this is used to prevent duplicates (unique) - std::vector m_commentLocations; + std::set m_commentLocations; - std::unordered_set m_serializedErrors; // this is used to prevent duplicates (unique) + std::set m_errorsIndex; // this is used to prevent duplicates (unique) std::vector m_errors; Id m_nextId; diff --git a/src/lib/data/storage/type/StorageCommentLocation.h b/src/lib/data/storage/type/StorageCommentLocation.h index 7bf6a07a..b7bb66a8 100644 --- a/src/lib/data/storage/type/StorageCommentLocation.h +++ b/src/lib/data/storage/type/StorageCommentLocation.h @@ -21,6 +21,30 @@ struct StorageCommentLocationData , endCol(endCol) {} + bool operator<(const StorageCommentLocationData& other) const + { + if (fileNodeId != other.fileNodeId) + { + return fileNodeId < other.fileNodeId; + } + else if (startLine != other.startLine) + { + return startLine < other.startLine; + } + else if (startCol != other.startCol) + { + return startCol < other.startCol; + } + else if (endLine != other.endLine) + { + return endLine < other.endLine; + } + else + { + return endCol < other.endCol; + } + } + Id fileNodeId; uint startLine; uint startCol; diff --git a/src/lib/data/storage/type/StorageComponentAccess.h b/src/lib/data/storage/type/StorageComponentAccess.h index 4af6da49..3d2eb03b 100644 --- a/src/lib/data/storage/type/StorageComponentAccess.h +++ b/src/lib/data/storage/type/StorageComponentAccess.h @@ -15,6 +15,11 @@ struct StorageComponentAccess , type(type) {} + bool operator<(const StorageComponentAccess& other) const + { + return nodeId < other.nodeId; + } + Id nodeId; int type; }; diff --git a/src/lib/data/storage/type/StorageError.h b/src/lib/data/storage/type/StorageError.h index 72260d61..1c4cabc8 100644 --- a/src/lib/data/storage/type/StorageError.h +++ b/src/lib/data/storage/type/StorageError.h @@ -36,6 +36,26 @@ struct StorageErrorData , indexed(indexed) {} + bool operator<(const StorageErrorData& other) const + { + if (message != other.message) + { + return message < other.message; + } + else if (filePath != other.filePath) + { + return filePath < other.filePath; + } + else if (lineNumber != other.lineNumber) + { + return lineNumber < other.lineNumber; + } + else + { + return columnNumber < other.columnNumber; + } + } + std::wstring message; std::wstring filePath; diff --git a/src/lib/data/storage/type/StorageFile.h b/src/lib/data/storage/type/StorageFile.h index 808dabcd..96686daa 100644 --- a/src/lib/data/storage/type/StorageFile.h +++ b/src/lib/data/storage/type/StorageFile.h @@ -31,6 +31,11 @@ struct StorageFile , complete(complete) {} + bool operator<(const StorageFile& other) const + { + return filePath < other.filePath; + } + Id id; std::wstring filePath; std::string modificationTime; diff --git a/src/lib/data/storage/type/StorageLocalSymbol.h b/src/lib/data/storage/type/StorageLocalSymbol.h index b1cccf2e..3c4f4c0d 100644 --- a/src/lib/data/storage/type/StorageLocalSymbol.h +++ b/src/lib/data/storage/type/StorageLocalSymbol.h @@ -15,6 +15,11 @@ struct StorageLocalSymbolData : name(std::move(name)) {} + bool operator<(const StorageLocalSymbolData& other) const + { + return name < other.name; + } + std::wstring name; }; diff --git a/src/lib/data/storage/type/StorageNode.h b/src/lib/data/storage/type/StorageNode.h index b77b5166..e2f8b2af 100644 --- a/src/lib/data/storage/type/StorageNode.h +++ b/src/lib/data/storage/type/StorageNode.h @@ -17,6 +17,11 @@ struct StorageNodeData , serializedName(std::move(serializedName)) {} + bool operator<(const StorageNodeData& other) const + { + return serializedName < other.serializedName; + } + int type; std::wstring serializedName; }; diff --git a/src/lib/data/storage/type/StorageOccurrence.h b/src/lib/data/storage/type/StorageOccurrence.h index 00d2946d..61e35914 100644 --- a/src/lib/data/storage/type/StorageOccurrence.h +++ b/src/lib/data/storage/type/StorageOccurrence.h @@ -15,6 +15,18 @@ struct StorageOccurrence , sourceLocationId(sourceLocationId) {} + bool operator<(const StorageOccurrence& other) const + { + if (elementId != other.elementId) + { + return elementId < other.elementId; + } + else + { + return sourceLocationId < other.sourceLocationId; + } + } + Id elementId; Id sourceLocationId; }; diff --git a/src/lib/data/storage/type/StorageSourceLocation.h b/src/lib/data/storage/type/StorageSourceLocation.h index 2be0ce95..f70280d6 100644 --- a/src/lib/data/storage/type/StorageSourceLocation.h +++ b/src/lib/data/storage/type/StorageSourceLocation.h @@ -23,6 +23,34 @@ struct StorageSourceLocationData , type(type) {} + bool operator<(const StorageSourceLocationData& other) const + { + if (fileNodeId != other.fileNodeId) + { + return fileNodeId < other.fileNodeId; + } + else if (startLine != other.startLine) + { + return startLine < other.startLine; + } + else if (startCol != other.startCol) + { + return startCol < other.startCol; + } + else if (endLine != other.endLine) + { + return endLine < other.endLine; + } + else if (endCol != other.endCol) + { + return endCol < other.endCol; + } + else + { + return type < other.type; + } + } + Id fileNodeId; uint startLine; uint startCol; diff --git a/src/lib/utility/utility.h b/src/lib/utility/utility.h index 1c7f0372..275f8300 100644 --- a/src/lib/utility/utility.h +++ b/src/lib/utility/utility.h @@ -221,6 +221,7 @@ template std::vector utility::toVector(const std::deque& d) { std::vector v; + v.reserve(d.size()); v.insert(v.begin(), d.begin(), d.end()); return v; } @@ -229,6 +230,7 @@ template std::vector utility::toVector(const std::set& d) { std::vector v; + v.reserve(d.size()); v.insert(v.begin(), d.begin(), d.end()); return v; } @@ -236,8 +238,7 @@ std::vector utility::toVector(const std::set& d) template std::set utility::toSet(const std::vector& v) { - std::set s(v.begin(), v.end()); - return s; + return std::set(v.begin(), v.end()); } template