[A bunch of the team met up today to hammer out some decisions.]
In brief: for strings that are known to be Unicode (that is, not
random byte strings read from a file), we will migrate towards using
string16. This means all places we use wstring should be split into
the appropriate types:
- byte strings should be string or vectors of chars
- paths should be FilePath
- urls should be GURL
- UI strings, etc. should be string16.
string16 uses UTF-16 underneath. It's equivalent to wstring on
Windows, but wstring involves 4-byte characters on Linux/Mac.
Some important factors were:
- we don't have too many strings in this category (with the huge
exception of WebKit), so memory usage isn't much of an issue
- it's the native string type of Windows, Mac, and WebKit
- we want it to be explicit (i.e. a compile error) when you
accidentally use a byte string in a place where we should know the
encoding (which std::string and UTF-8 doesn't allow)
- we still use UTF-8 in some places (like the history full-text
database) where space is more of a concern
The question that always comes up as a result is "what to do about literals?"
Use ASCIIToUTF16("foo"), assuming of course your literal is ASCII.
This is basically the same speed as constructing a wstring out of a
wchar_t* literal since it's just a copy with 0-extend on each one.
Brett
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
For Windows it is inefficient - both speed wise and memory wise, as
there are many places where we need wchar_t literals (all of the API
calls, for example). So creation of extra std::(w)string is wasteful.
G.
-scott
But why do not have it if we can (as Victor pointed out)?
Little waste is still waste. It adds up :).
Yes, but what I am saying is that if we have a STRING16() macro for
literals it will be string16 on all platforms, thus adding to clarity
and reducing both bugs and inefficiency!
Static array of literals. In you case we are *forced* to use
std::*string with destructor being called on program exit.
In my case it just static POD.
--