The Great Refactor: Step 1: Replace nstrdup
Date: Tuesday, June 22 @ 15:50:05 CDT
Topic: The Great Refactor


Replace the local nstrdup() implementation with standard strdup() one. Primarily a performance increase, but this also has several major advantages... First advantage: Decoupling
The biggest performance issue in xMule right now is its module interdependencies. In an oportune environment, every single .h file should include only a minimal number of files. Decoupling decreases compile time dramatically, makes programs less likely to segfault, and decreases CPU and memory usage.

Second advantage: Standardization
By using the standard strdup instead of our own implementation of nstrdup, we remove any and all unexpected behaviorisms that differ from the norm. This is incredibly noticeable when it comes to unicoding xMule, as wxChar* are handled appropriately by strdup() but get mangled with nstrdup(). Third advantage: Decrease in memory leaks:
Our nstrdup() assigned memory via new, which is overkill, because the size of the source string is always defined, and because char* has no c_tor()s or d_tor()s, yet wxChar* does. This means that unexpected behaviorisms crop up because C++ tries to free() char* and in this instance, delete[] is the appropriate mechanism. The change(s) specified above were made at FileRevCount PartFile.cpp1.12516 packets.cpp1.366 BaseClient.cpp1.905 KnownFile.cpp1.494 AddFileThread.cpp1.332 Preferences.cpp1.811 UploadClient.cpp1.381 otherfunctions.cpp1.531 --> The final results are that only PartFile.cpp needed otherfunctions.h after this decoupling effort. One out of 8, not bad for one inefficient function :-) Compile times Before6m27.87s After5m 55.03s A diff of all changes.





This article comes from xMule: A P2P Client derived from eMule
http://www.xmule.ws/phpnuke

The URL for this story is:
http://www.xmule.ws/phpnuke/modules.php?name=News&file=article&sid=13