[PATCH] MC: Use StringRef to avoid strcmp/strlen on non-null-term'd strings.

Will Dietz w at wdtz.org
Sat Oct 12 20:52:27 PDT 2013


See attached, explanation from commit message follows.

----------------------------------

This can happen when processing command line arguments, which
are often stored as std::string's and later turned into
StringRef's via std::string::data().  Unfortunately this
is not guaranteed to return a null-terminated string
until C++11, causing breakage on platforms that don't do this.

Use of StringRef also simplifies the code a bit, as a bonus.

Note that the use of ".data()" is okay when printing the
lists of recognized -mcpu options and similar code, since
the tables themselves are statically populated with C-strings
that are guaranteed to be null-terminated.

----------------------------------

Two concerns I have with this change:

* Resulting increase in size/memory use of the tables due to storing
size explicitly
* Possible initialization time increases.

Are either concerns something to be sufficiently concerned about that
they should be measured, and if so any recommenedations on how I might
do so?

Regarding initialization time, I tried running llvm-mc before and
after assembling a small file, which showed no ignificant difference
across many runs.  I'm not confident in the validity of this test,
however.

If these are valid concerns, an alternative is to just construct a
null-terminated
string on-the-fly when querying the tables (since these are the strings that are
potentially lacking the terminators).  Let me know if this sounds preferrable.

~Will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-MC-Use-StringRef-to-avoid-strcmp-strlen-on-non-null-.patch
Type: application/octet-stream
Size: 5913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131012/1d469dce/attachment.obj>


More information about the llvm-commits mailing list