CREATING AN OPTIMIZED STRING TYPE FOR CCP
(it covers some basic stuff and gives a few tips & tricks too)
HISTORY
Version 1.0: Document finally done
This document was last modified on: 7/2/08 1:32 AM
You may have three questions right now. Let's take a look at them and their answers:
Why a new String type? Generic string types, like std::string, are good for their common use. You basically create a few of these,
concatenate them, change their values, pass them around and display them. Of course you can do way more things than that, but if
you have special needs you may want to have special solutions... in this case, a special new string type.
What's the optimization? The purpose of this string type is to provide an efficient way to create substrings when you seldom change
the contents of both the substrings and the original string. When you need to create a substring, the generic string types commonly
allocate memory and copy the selected piece of the source string to the new buffer in the destination string. It may also happen that
assigning a string causes allocation and contents copying; however, it may be also possible that the implementation uses
Copy-on-Write (if you don't know what it means, you'll see it later), making the assignment operation faster, but it may NOT do it.
What the heck is CCP? CCP is the name of a library I created to preprocess C++ code. If you think about the process, or if you check
the code, most of the string manipulations are creating substrings and assigning strings. Speeding up string manipulations in these
two aspects should speed up the library too. Since one of the design decisions was to parameterize the base types, replacing the
string type is quite easy.
You see the reasoning behind this now, right? Although, another question may arise, and it's good if that question, or related, rises
in you:
Are you sure this is the right place to start optimizing? No, I'm not sure, it's just a SWAG (Scientific Wild Ass Guess), but that's not all. I
do really want to implement such a strin