avoid creating html-entity AA at start-up - 10% speed up(!)

This is not even remotely funny creating this huge AA
at run-time took around 10% of the whole time to lex std.datetime
This commit is contained in:
Dmitry Olshansky 2013-02-23 00:00:19 +04:00
parent 119c6b917d
commit e4baf99ca4
3 changed files with 2143 additions and 2140 deletions

10
main.d
View File

@ -97,9 +97,9 @@ int main(string[] args)
{
string[] importDirs;
bool sloc;
/+bool dotComplete;+/
/+bool json;+/
/+bool parenComplete;+/
bool dotComplete;
bool json;
bool parenComplete;
bool highlight;
bool ctags;
bool recursiveCtags;
@ -110,8 +110,8 @@ int main(string[] args)
try
{
getopt(args, "I", &importDirs,/+ "dotComplete|d", &dotComplete,+/ "sloc|l", &sloc,
/+"json|j", &json,+/ /+"parenComplete|p", &parenComplete,+/ "highlight", &highlight,
getopt(args, "I", &importDirs, "dotComplete|d", &dotComplete, "sloc|l", &sloc,
"json|j", &json, "parenComplete|p", &parenComplete, "highlight", &highlight,
"ctags|c", &ctags, "recursive|r|R", &recursiveCtags, "help|h", &help,
"tokenCount", &tokenCount, "frequencyCount", &frequencyCount);
}

File diff suppressed because it is too large Load Diff

View File

@ -2010,15 +2010,18 @@ private:
return idx;
}
}
auto chunk = buffer[0..idx];
auto entity = cast(string)chunk in characterEntities;
if (entity is null)
//TODO: avoid looking up as UTF string, use raw bytes
string chunk = cast(string)buffer[0..idx];
auto names = assumeSorted(map!"a.name"(characterEntities));
auto place = names.lowerBound(chunk).length;
if (place == names.length || names[place] != chunk)
{
errorMessage("Invalid character entity \"&%s;\""
.format(cast(string) chunk));
return 1;
}
dest.put(cast(ubyte[]) (*entity)[0..$]);
auto entity = characterEntities[place].value;
dest.put(cast(ubyte[]) entity);
return entity.length;
default:
errorMessage("Invalid escape sequence");