data: Improved data storing performance in IntermediateStorage

This commit is contained in:
Eberhard Graether
2018-08-27 23:37:24 +02:00
parent c0984b2ca4
commit 470a8a3920
13 changed files with 280 additions and 290 deletions
@@ -23,10 +23,11 @@ SharedIntermediateStorage::~SharedIntermediateStorage()
std::vector<StorageFile> SharedIntermediateStorage::getStorageFiles() const
{
std::vector<StorageFile> 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<StorageFile>&
std::vector<StorageNode> SharedIntermediateStorage::getStorageNodes() const
{
std::vector<StorageNode> 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<StorageNode>&
std::vector<StorageSymbol> SharedIntermediateStorage::getStorageSymbols() const
{
std::vector<StorageSymbol> 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<StorageSymbo
std::vector<StorageEdge> SharedIntermediateStorage::getStorageEdges() const
{
std::vector<StorageEdge> 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<StorageEdge>&
}
}
std::vector<StorageLocalSymbol> SharedIntermediateStorage::getStorageLocalSymbols() const
std::set<StorageLocalSymbol> SharedIntermediateStorage::getStorageLocalSymbols() const
{
std::vector<StorageLocalSymbol> result;
std::set<StorageLocalSymbol> 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<StorageLocalSymbol>& storageLocalSymbols)
void SharedIntermediateStorage::setStorageLocalSymbols(const std::set<StorageLocalSymbol>& 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<StorageSourceLocation> SharedIntermediateStorage::getStorageSourceLocations() const
std::set<StorageSourceLocation> SharedIntermediateStorage::getStorageSourceLocations() const
{
std::vector<StorageSourceLocation> result;
std::set<StorageSourceLocation> 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<StorageSourceLocation>& storageSourceLocations)
void SharedIntermediateStorage::setStorageSourceLocations(const std::set<StorageSourceLocation>& 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<StorageOccurrence> SharedIntermediateStorage::getStorageOccurrences() const
std::set<StorageOccurrence> SharedIntermediateStorage::getStorageOccurrences() const
{
std::vector<StorageOccurrence> result;
std::set<StorageOccurrence> 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<StorageOccurrence>& storageOccurences)
void SharedIntermediateStorage::setStorageOccurrences(const std::set<StorageOccurrence>& 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<StorageComponentAccess> SharedIntermediateStorage::getStorageComponentAccesses() const
std::set<StorageComponentAccess> SharedIntermediateStorage::getStorageComponentAccesses() const
{
std::vector<StorageComponentAccess> result;
std::set<StorageComponentAccess> 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<StorageComponentAccess>& storageComponentAccesses)
void SharedIntermediateStorage::setStorageComponentAccesses(const std::set<StorageComponentAccess>& 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<StorageCommentLocationData> SharedIntermediateStorage::getStorageCommentLocations() const
std::set<StorageCommentLocationData> SharedIntermediateStorage::getStorageCommentLocations() const
{
std::vector<StorageCommentLocationData> result;
std::set<StorageCommentLocationData> 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<StorageCommentLocationData>& commentLocations)
void SharedIntermediateStorage::setStorageCommentLocations(const std::set<StorageCommentLocationData>& 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<StorageErrorData> SharedIntermediateStorage::getStorageErrors() const
{
std::vector<StorageErrorData> 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;
@@ -22,20 +22,20 @@ public:
std::vector<StorageEdge> getStorageEdges() const;
void setStorageEdges(const std::vector<StorageEdge>& storageEdges);
std::vector<StorageLocalSymbol> getStorageLocalSymbols() const;
void setStorageLocalSymbols(const std::vector<StorageLocalSymbol>& storageLocalSymbols);
std::set<StorageLocalSymbol> getStorageLocalSymbols() const;
void setStorageLocalSymbols(const std::set<StorageLocalSymbol>& storageLocalSymbols);
std::vector<StorageSourceLocation> getStorageSourceLocations() const;
void setStorageSourceLocations(const std::vector<StorageSourceLocation>& storageSourceLocations);
std::set<StorageSourceLocation> getStorageSourceLocations() const;
void setStorageSourceLocations(const std::set<StorageSourceLocation>& storageSourceLocations);
std::vector<StorageOccurrence> getStorageOccurrences() const;
void setStorageOccurrences(const std::vector<StorageOccurrence>& storageOccurences);
std::set<StorageOccurrence> getStorageOccurrences() const;
void setStorageOccurrences(const std::set<StorageOccurrence>& storageOccurences);
std::vector<StorageComponentAccess> getStorageComponentAccesses() const;
void setStorageComponentAccesses(const std::vector<StorageComponentAccess>& storageComponentAccesses);
std::set<StorageComponentAccess> getStorageComponentAccesses() const;
void setStorageComponentAccesses(const std::set<StorageComponentAccess>& storageComponentAccesses);
std::vector<StorageCommentLocationData> getStorageCommentLocations() const;
void setStorageCommentLocations(const std::vector<StorageCommentLocationData>& commentLocations);
std::set<StorageCommentLocationData> getStorageCommentLocations() const;
void setStorageCommentLocations(const std::set<StorageCommentLocationData>& commentLocations);
std::vector<StorageErrorData> getStorageErrors() const;
void setStorageErrors(const std::vector<StorageErrorData>& errors);
+98 -206
View File
@@ -1,6 +1,6 @@
#include "data/storage/IntermediateStorage.h"
#include <set>
#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<std::wstring, size_t>::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<std::wstring, size_t>::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<std::wstring, size_t>::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<std::wstring, StorageLocalSymbol>::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<std::wstring, StorageSourceLocation>::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<StorageOccurrence>& 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<void(const StorageNode& /*da
void IntermediateStorage::forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const
{
for (std::vector<StorageFile>::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<void(const StorageSymbol& /*data*/)> callback) const
{
for (std::vector<StorageSymbol>::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<void(const StorageEdge& /*da
void IntermediateStorage::forEachLocalSymbol(std::function<void(const StorageLocalSymbol& /*data*/)> callback) const
{
for (std::unordered_map<std::wstring, StorageLocalSymbol>::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<void(const StorageSourceLocation& /*data*/)> callback) const
{
for (std::unordered_map<std::wstring, StorageSourceLocation>::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<void(const StorageOccurrence& /*data*/)> callback) const
{
for (std::vector<StorageOccurrence>::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<void(const StorageComponentAccess& /*data*/)> callback) const
{
for (std::vector<StorageComponentAccess>::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<void(const StorageCommentLocationData& /*data*/)> callback) const
{
for (std::vector<StorageCommentLocationData>::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<void(const StorageErrorData& /*data*/)> callback) const
{
for (std::vector<StorageErrorData>::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<StorageEdge>& IntermediateStorage::getStorageEdges() const
return m_edges;
}
std::vector<StorageLocalSymbol> IntermediateStorage::getStorageLocalSymbols() const
const std::set<StorageLocalSymbol>& IntermediateStorage::getStorageLocalSymbols() const
{
std::vector<StorageLocalSymbol> localSymbol;
localSymbol.reserve(m_localSymbols.size());
for (const auto& it: m_localSymbols)
{
localSymbol.push_back(it.second);
}
return localSymbol;
return m_localSymbols;
}
std::vector<StorageSourceLocation> IntermediateStorage::getStorageSourceLocations() const
const std::set<StorageSourceLocation>& IntermediateStorage::getStorageSourceLocations() const
{
std::vector<StorageSourceLocation> 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<StorageOccurrence>& IntermediateStorage::getStorageOccurrences() const
const std::set<StorageOccurrence>& IntermediateStorage::getStorageOccurrences() const
{
return m_occurrences;
}
const std::vector<StorageComponentAccess>& IntermediateStorage::getComponentAccesses() const
const std::set<StorageComponentAccess>& IntermediateStorage::getComponentAccesses() const
{
return m_componentAccesses;
}
const std::vector<StorageCommentLocationData>& IntermediateStorage::getCommentLocations() const
const std::set<StorageCommentLocationData>& IntermediateStorage::getCommentLocations() const
{
return m_commentLocations;
}
@@ -385,74 +349,73 @@ const std::vector<StorageErrorData>& IntermediateStorage::getErrors() const
return m_errors;
}
void IntermediateStorage::setStorageNodes(const std::vector<StorageNode>& storageNodes)
void IntermediateStorage::setStorageNodes(std::vector<StorageNode> 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<StorageFile>& storageFiles)
void IntermediateStorage::setStorageFiles(std::vector<StorageFile> 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<StorageSymbol>& storageSymbols)
void IntermediateStorage::setStorageSymbols(std::vector<StorageSymbol> storageSymbols)
{
m_symbols = storageSymbols;
m_symbols = std::move(storageSymbols);
}
void IntermediateStorage::setStorageEdges(const std::vector<StorageEdge>& storageEdges)
void IntermediateStorage::setStorageEdges(std::vector<StorageEdge> 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<StorageLocalSymbol>& storageLocalSymbols)
void IntermediateStorage::setStorageLocalSymbols(std::set<StorageLocalSymbol> 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<StorageSourceLocation>& storageSourceLocations)
void IntermediateStorage::setStorageSourceLocations(std::set<StorageSourceLocation> 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<StorageOccurrence>& storageOccurrences)
void IntermediateStorage::setStorageOccurrences(std::set<StorageOccurrence> storageOccurrences)
{
m_occurrences = storageOccurrences;
m_occurrences = std::move(storageOccurrences);
}
void IntermediateStorage::setComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses)
void IntermediateStorage::setComponentAccesses(std::set<StorageComponentAccess> componentAccesses)
{
m_componentAccesses = componentAccesses;
m_componentAccesses = std::move(componentAccesses);
}
void IntermediateStorage::setCommentLocations(const std::vector<StorageCommentLocationData>& commentLocations)
void IntermediateStorage::setCommentLocations(std::set<StorageCommentLocationData> commentLocations)
{
m_commentLocations = commentLocations;
m_commentLocations = std::move(commentLocations);
}
void IntermediateStorage::setErrors(const std::vector<StorageErrorData>& errors)
void IntermediateStorage::setErrors(std::vector<StorageErrorData> 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)
);
}
+25 -37
View File
@@ -3,8 +3,7 @@
#include <memory>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include "data/storage/type/StorageCommentLocation.h"
#include "data/storage/type/StorageComponentAccess.h"
@@ -60,63 +59,52 @@ public:
const std::vector<StorageFile>& getStorageFiles() const;
const std::vector<StorageSymbol>& getStorageSymbols() const;
const std::vector<StorageEdge>& getStorageEdges() const;
std::vector<StorageLocalSymbol> getStorageLocalSymbols() const;
std::vector<StorageSourceLocation> getStorageSourceLocations() const;
const std::vector<StorageOccurrence>& getStorageOccurrences() const;
const std::vector<StorageComponentAccess>& getComponentAccesses() const;
const std::vector<StorageCommentLocationData>& getCommentLocations() const;
const std::set<StorageLocalSymbol>& getStorageLocalSymbols() const;
const std::set<StorageSourceLocation>& getStorageSourceLocations() const;
const std::set<StorageOccurrence>& getStorageOccurrences() const;
const std::set<StorageComponentAccess>& getComponentAccesses() const;
const std::set<StorageCommentLocationData>& getCommentLocations() const;
const std::vector<StorageErrorData>& getErrors() const;
void setStorageNodes(const std::vector<StorageNode>& storageNodes);
void setStorageFiles(const std::vector<StorageFile>& storageFiles);
void setStorageSymbols(const std::vector<StorageSymbol>& storageSymbols);
void setStorageEdges(const std::vector<StorageEdge>& storageEdges);
void setStorageLocalSymbols(const std::vector<StorageLocalSymbol>& storageLocalSymbols);
void setStorageSourceLocations(const std::vector<StorageSourceLocation>& storageSourceLocations);
void setStorageOccurrences(const std::vector<StorageOccurrence>& storageOccurrences);
void setComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses);
void setCommentLocations(const std::vector<StorageCommentLocationData>& commentLocations);
void setErrors(const std::vector<StorageErrorData>& errors);
void setStorageNodes(std::vector<StorageNode> storageNodes);
void setStorageFiles(std::vector<StorageFile> storageFiles);
void setStorageSymbols(std::vector<StorageSymbol> storageSymbols);
void setStorageEdges(std::vector<StorageEdge> storageEdges);
void setStorageLocalSymbols(std::set<StorageLocalSymbol> storageLocalSymbols);
void setStorageSourceLocations(std::set<StorageSourceLocation> storageSourceLocations);
void setStorageOccurrences(std::set<StorageOccurrence> storageOccurrences);
void setComponentAccesses(std::set<StorageComponentAccess> componentAccesses);
void setCommentLocations(std::set<StorageCommentLocationData> commentLocations);
void setErrors(std::vector<StorageErrorData> 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<std::wstring, size_t> m_nodesIndex;
std::map<StorageNodeData, size_t> m_nodesIndex;
std::vector<StorageNode> m_nodes;
std::unordered_map<std::wstring, size_t> m_serializedFiles; // this is used to prevent duplicates (unique)
std::map<StorageFile, size_t> m_filesIndex; // this is used to prevent duplicates (unique)
std::vector<StorageFile> m_files;
std::vector<StorageSymbol> m_symbols;
std::unordered_map<std::wstring, size_t> m_edgesIndex;
std::map<StorageEdgeData, size_t> m_edgesIndex;
std::vector<StorageEdge> m_edges;
std::unordered_map<std::wstring, StorageLocalSymbol> m_localSymbols;
std::set<StorageLocalSymbol> m_localSymbols;
std::unordered_map<std::wstring, StorageSourceLocation> m_sourceLocations;
std::set<StorageSourceLocation> m_sourceLocations;
std::unordered_set<std::wstring> m_serializedOccurrences; // this is used to prevent duplicates (unique)
std::vector<StorageOccurrence> m_occurrences;
std::set<StorageOccurrence> m_occurrences;
std::unordered_set<std::wstring> m_serializedComponentAccesses; // this is used to prevent duplicates (unique)
std::vector<StorageComponentAccess> m_componentAccesses;
std::set<StorageComponentAccess> m_componentAccesses;
std::unordered_set<std::wstring> m_serializedCommentLocations; // this is used to prevent duplicates (unique)
std::vector<StorageCommentLocationData> m_commentLocations;
std::set<StorageCommentLocationData> m_commentLocations;
std::unordered_set<std::wstring> m_serializedErrors; // this is used to prevent duplicates (unique)
std::set<StorageErrorData> m_errorsIndex; // this is used to prevent duplicates (unique)
std::vector<StorageErrorData> m_errors;
Id m_nextId;
@@ -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;
@@ -15,6 +15,11 @@ struct StorageComponentAccess
, type(type)
{}
bool operator<(const StorageComponentAccess& other) const
{
return nodeId < other.nodeId;
}
Id nodeId;
int type;
};
+20
View File
@@ -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;
+5
View File
@@ -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;
@@ -15,6 +15,11 @@ struct StorageLocalSymbolData
: name(std::move(name))
{}
bool operator<(const StorageLocalSymbolData& other) const
{
return name < other.name;
}
std::wstring name;
};
+5
View File
@@ -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;
};
@@ -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;
};
@@ -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;
+3 -2
View File
@@ -221,6 +221,7 @@ template<typename T>
std::vector<T> utility::toVector(const std::deque<T>& d)
{
std::vector<T> v;
v.reserve(d.size());
v.insert(v.begin(), d.begin(), d.end());
return v;
}
@@ -229,6 +230,7 @@ template<typename T>
std::vector<T> utility::toVector(const std::set<T>& d)
{
std::vector<T> v;
v.reserve(d.size());
v.insert(v.begin(), d.begin(), d.end());
return v;
}
@@ -236,8 +238,7 @@ std::vector<T> utility::toVector(const std::set<T>& d)
template<typename T>
std::set<T> utility::toSet(const std::vector<T>& v)
{
std::set<T> s(v.begin(), v.end());
return s;
return std::set<T>(v.begin(), v.end());
}
template<typename T>