Opened 11 years ago
Closed 10 years ago
#2005 closed enhancement (wontfix)
[PATCH] CParser removed + Hotkey patch
Reported by: | Jorma Rebane | Owned by: | Jorma Rebane |
---|---|---|---|
Priority: | Must Have | Milestone: | |
Component: | Core engine | Keywords: | patch performance memory |
Cc: | Patch: |
Description (last modified by )
1) CParser was a horrible freak of a regex parser. It left a horrible memory footprint and slowed the game down during load times. After replacing it with something much much simpler, the game startup and exit time was noticeably faster (alloc/dealloc overhead probably).
How CTokenizer works:
A string tokenizer doesn't own the string or memory you give it, so make sure the resource exists while you parse.
std::string input = " toggle = 'Alt+F' = else "; std::string key, value; CTokenizer tokenizer(input); CTokenizer token; if(tokenizer.next(token, '=')) // split tokens at '=' { // if a token was availablee (no EOS) token.trim().toString(key); // trim whitespace, then tostr // key == "toggle" } if(tokenizer.next(token, '=')) { token.trim(" '").toString(value); // trim spaces and ' // value == "Alt+F" }
2) Hotkey patch is a fix that was pretty easy to make - it makes hotkey triggers a lot faster and memory efficient than they used to be. No real functionality changed inside 0 A.D. - only the stuff under the hood got changed.
Change History (22)
comment:1 by , 11 years ago
Description: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:2 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:3 by , 11 years ago
Status: | reopened → new |
---|
comment:4 by , 11 years ago
follow-up: 6 comment:5 by , 11 years ago
Infact, I'm getting a few errors during compile. Here is a pastie with all of them: http://pastie.org/8081539
follow-up: 7 comment:6 by , 11 years ago
Replying to k776:
Infact, I'm getting a few errors during compile. Here is a pastie with all of them: http://pastie.org/8081539
Hi k776, thanks for taking a look at the patch. :) What version of GCC did you compile with? 4.2 or 4.7? std::string::front() and std::string::back() are standard functions, but I can easily replace them with something different.
As for the warnings of 'redundant redefinition of wcsdup', it seems to be some compatibility code in lib/posix/posix.h:
#if OS_MACOSX # define EMULATE_WCSDUP 1 # define EMULATE_WCSCASECMP 1 #else # define EMULATE_WCSDUP 0 # define EMULATE_WCSCASECMP 0 #endif #if EMULATE_WCSDUP extern wchar_t* wcsdup(const wchar_t* str); #endif #if EMULATE_WCSCASECMP extern int wcscasecmp(const wchar_t* s1, const wchar_t* s2); #endif
Perhaps you are running a newer compiler that now has wcsdup and wcscasecmp on MAC? In this case we'd have to update the condition:
Edit: Thanks for Markus for pointing out a mistake in the emulation condition. :)
// emulate for < 4.0 or < 4.7 #if OS_MACOSX && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)) # define EMULATE_WCSDUP 1 # define EMULATE_WCSCASECMP 1 #else # define EMULATE_WCSDUP 0 # define EMULATE_WCSCASECMP 0 #endif
follow-up: 8 comment:7 by , 11 years ago
comment:8 by , 11 years ago
comment:9 by , 11 years ago
Summary: | CParser replacement + Hotkey code patch → [PATCH] CParser replacement + Hotkey code patch |
---|
comment:10 by , 11 years ago
Summary: | [PATCH] CParser replacement + Hotkey code patch → [PATCH] CParser removed + Hotkey patch |
---|
comment:11 by , 11 years ago
Keywords: | patch review added; parser performance strtok hotkey removed |
---|
comment:12 by , 11 years ago
Priority: | Should Have → Must Have |
---|
comment:13 by , 11 years ago
Milestone: | Backlog → Alpha 14 |
---|
comment:14 by , 11 years ago
Keywords: | performance memory added |
---|
comment:15 by , 11 years ago
Updated the patch file. Removed setlocale(LC_NUMERIC, "C") and atof calls. As a suggestion from leper, just used the simplest atof implementation possible, which should cover our needs.
Also fixed a bug in Hotkey parsing. Now duplicate/secondary hotkey definitions are ignored.
comment:16 by , 11 years ago
Description: | modified (diff) |
---|
comment:17 by , 11 years ago
Fixed a small parsing bug that popped up after removing C atof. Empty tokens were sometimes not discarded. Using _tofloat to parse floats now; some slight optimizations added.
follow-up: 19 comment:18 by , 11 years ago
Applied the latest patch and still getting compile errors. Here is build log and errors: http://pastie.org/8096337
Compiling with GCC 4.2.1.
comment:19 by , 11 years ago
Replying to k776: Looks like I accidentally left out TerrainManager.cpp. It's already becoming difficult to keep track of which changes apply to which patch... :/
comment:20 by , 11 years ago
Since my patches have started overlapping each-other, its impossible to submit one here. Check the original performance ticket #1995 for the cumulative patch.
comment:21 by , 11 years ago
Milestone: | Alpha 14 → Alpha 15 |
---|
comment:22 by , 10 years ago
Keywords: | review removed |
---|---|
Milestone: | Alpha 15 |
Resolution: | → wontfix |
Status: | new → closed |
Closing these tickets as no further active development is expected. See Philip's megapatch-split git branch for an attempt at splitting megapatch into it's separate parts: http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/megapatch-split
Compiling error on my mac: