Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Macro replacement in CC(tokenizer) suggestion
oBFusCATed:
Another option is to replace std::map with std::tr1::unordered_map, it if is available (gcc > 4.x.y, not sure which is the minimal x thought)
std::tr1::unordered_map is hash map, so the lookup is O(1) operation.
ollydbg:
--- Quote from: thomas on June 30, 2009, 12:23:17 pm ---
with something like:
if(token.IsEmpty() || (token == one_constant) || (token == two_constant) || (token == three_constant))
return token;
else
return the_map.find(token);
--- End quote ---
Hi, thomas, Thanks for the full explanation about your point.
But I think you still misunderstand my mind. :(
Look at the code in DoGetToken(), I have made a pseudo code below. We can add a bool variable
--- Code: ---
bool NeedReplacement;
if (c == '_' || wxIsalpha(c))
{
..........
NeedReplacement = true;
}
else if (wxIsdigit(CurrentChar()))
{
.........
NeedReplacement = false;
}
else if (CurrentChar() == '"' || CurrentChar() == '\'')
{
......
NeedReplacement = false;
}
else if (CurrentChar() == '(')
{
......
NeedReplacement = false;
}
else
{
.......
}
if(!NeedReplacement)
return token;
else
return the_map.find(token);
--- End code ---
Because we have already know the information of the current token, we can still save quite a lot of time. :D
ollydbg:
--- Quote from: oBFusCATed on June 30, 2009, 01:37:44 pm ---Another option is to replace std::map with std::tr1::unordered_map, it if is available (gcc > 4.x.y, not sure which is the minimal x thought)
std::tr1::unordered_map is hash map, so the lookup is O(1) operation.
--- End quote ---
This is the great news.
If it is really true that hash map runs faster, I do suggest change to use std::tr1::unordered_map, thanks for the suggestion!!!
Kazade:
--- Quote from: oBFusCATed on June 30, 2009, 01:37:44 pm ---Another option is to replace std::map with std::tr1::unordered_map, it if is available (gcc > 4.x.y, not sure which is the minimal x thought)
std::tr1::unordered_map is hash map, so the lookup is O(1) operation.
--- End quote ---
I personally have been using std::tr1::unordered_map for everything for ages (at least a year), I definitely think if it's available it should be used. Apparently GCC has a __GXX_EXPERIMENTAL_CXX0X__ macro. eg:
--- Code: ---#ifdef __GXX_EXPERIMENTAL_CXX0X__
typedef std::tr1::unordered_map CBMap;
#else
typedef std::map CBMap;
#endif
CBMap<wxString, wxString> myMap;
--- End code ---
or something like that.
oBFusCATed:
Kazade: unordered containers do not require the experimental c++-0x, they are in TR1
Navigation
[0] Message Index
[*] Previous page
Go to full version