summaryrefslogtreecommitdiffstats
path: root/tools/gn/command_format_unittest.cc
diff options
context:
space:
mode:
authorgeorgesak <georgesak@chromium.org>2014-12-02 17:10:29 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-03 01:10:44 +0000
commit7da6e9da88541615b6e709baa4ed6b05c40fcdcf (patch)
tree5d8cb270470640b6ea521547d1d14240bbb73842 /tools/gn/command_format_unittest.cc
parent3d4df94e080daaccf0c58ceb52e231883bcf2e55 (diff)
downloadchromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.zip
chromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.tar.gz
chromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.tar.bz2
Change preference APIs to take std::string instead of const char*.
The string can't be NULL, and most callers have std::strings already, so this makes the intent clearer and avoid unnecessary switch between std::string and const char*. Right now, the prefs are stored in char*, then converted to strings, then passed again as char*, only to be converted again, which creates the unnecessary temporary strings. For example, PrefValueStore::OnPrefValueChanged passes |key|, which is a string, as a const char* to PrefValueStore::NotifyPrefChanged, which then passes it to PrefNotifierImpl::OnPreferenceChanged as a string again. Our tests show that this change reduces on average by ~9% the number of total allocations in the browser process. Notes: - The underlying pref map in the PrefRegistry is based on string keys and thus any call to it, e.g. find(), needs to convert to string anyways at the bottom of the implementation so might as well force the string to be passed into the API originally. - A strict char* API, i.e. all the way into the pref map with a custom comparator/etc., would make memory harder to manage since we can't strictly force the caller to pass only pointers to constants in .rodata and would thus require explicit memory management. - Ideally, we would need a hybrid string class that manages the memory on demand. That way, it can point to hard coded strings with the memory management disabled or allocate a buffer that it will manage, to get the best of both worlds. BUG=438215 Review URL: https://codereview.chromium.org/753603002 Cr-Commit-Position: refs/heads/master@{#306514}
Diffstat (limited to 'tools/gn/command_format_unittest.cc')
0 files changed, 0 insertions, 0 deletions