Commit 3eaf0440 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: replace a tree by a hash

Be more environment friendly by using less trees.

Change-Id: I54d3b23d697a3b72a6a803688a8da0eddaad3e17
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent b9c64a39
......@@ -428,8 +428,7 @@ void TranslationUnit::getPosition(unsigned tokenOffset,
// If this token is expanded we already have the information directly from the expansion
// section header. Otherwise, we need to calculate it.
std::map<unsigned, std::pair<unsigned, unsigned> >::const_iterator it =
_expandedLineColumn.find(tokenOffset);
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tokenOffset);
if (it != _expandedLineColumn.end()) {
lineNumber = it->second.first;
columnNumber = it->second.second + 1;
......@@ -554,8 +553,7 @@ bool TranslationUnit::maybeSplitGreaterGreaterToken(unsigned tokenIndex)
_tokens->insert(_tokens->begin() + tokenIndex + 1, newGreater);
std::map<unsigned, std::pair<unsigned, unsigned> >::const_iterator it =
_expandedLineColumn.find(tok.offset);
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.offset);
if (it != _expandedLineColumn.end()) {
const std::pair<unsigned, unsigned> newPosition(it->second.first, it->second.second + 1);
_expandedLineColumn.insert(std::make_pair(newGreater.offset, newPosition));
......
......@@ -27,7 +27,18 @@
#include "DiagnosticClient.h"
#include <cstdio>
#include <vector>
#include <map>
#if !(__cplusplus > 199711L || __GXX_EXPERIMENTAL_CXX0X__ || _MSC_VER >= 1600 || defined( _LIBCPP_VERSION ))
#define USE_TR1
#endif
#if defined(_MSC_VER) && _MSC_VER < 1600
# include <map>
#elif defined(USE_TR1)
# include <tr1/unordered_map>
#else
# include <unordered_map>
#endif
namespace CPlusPlus {
......@@ -175,7 +186,15 @@ private:
std::vector<Token> *_comments;
std::vector<unsigned> _lineOffsets;
std::vector<PPLine> _ppLines;
std::map<unsigned, std::pair<unsigned, unsigned> > _expandedLineColumn; // TODO: Replace this for a hash
#if defined(_MSC_VER) && _MSC_VER < 1600
// MSVC2008 and earlier do not implement TR1.
typedef std::map<unsigned, std::pair<unsigned, unsigned> > TokenLineColumn;
#elif defined(USE_TR1)
typedef std::tr1::unordered_map<unsigned, std::pair<unsigned, unsigned> > TokenLineColumn;
#else
typedef std::unordered_map<unsigned, std::pair<unsigned, unsigned> > TokenLineColumn;
#endif
TokenLineColumn _expandedLineColumn;
MemoryPool *_pool;
AST *_ast;
TranslationUnit *_previousTranslationUnit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment