Store symbol names as a ImmutableString
This will enable compile-time initialization of built-in symbols as
well as reducing copying strings.
Most of the code that deals with names is changed to use
ImmutableString where it makes sense to avoid conversions.
The lexer/parser now allocate const char pointers into pool memory
instead of allocating TStrings. These are then converted to
ImmutableString upon entering TParseContext.
BUG=angleproject:2267
TEST=angle_unittests, angle_end2end_tests
Change-Id: I244d6271ea1ecf7150d4f89dfa388a7745a1150c
Reviewed-on: https://chromium-review.googlesource.com/881561
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/ImmutableStringBuilder.h b/src/compiler/translator/ImmutableStringBuilder.h
index 94dcc3b..5580f20 100644
--- a/src/compiler/translator/ImmutableStringBuilder.h
+++ b/src/compiler/translator/ImmutableStringBuilder.h
@@ -32,6 +32,28 @@
// This invalidates the ImmutableStringBuilder, so it should only be called once.
operator ImmutableString();
+ template <typename T>
+ void appendHex(T number)
+ {
+ ASSERT(mData != nullptr);
+ ASSERT(mPos + sizeof(T) * 2u <= mMaxLength);
+ int index = static_cast<int>(sizeof(T)) * 2 - 1;
+ // Loop through leading zeroes.
+ while (((number >> (index * 4)) & 0xfu) == 0 && index > 0)
+ {
+ --index;
+ }
+ // Write the rest of the hex digits.
+ while (index >= 0)
+ {
+ char digit = static_cast<char>((number >> (index * 4)) & 0xfu);
+ char digitChar = digit < 10 ? digit + '0' : digit + 'a';
+ mData[mPos++] = digitChar;
+ --index;
+ }
+ return;
+ }
+
private:
inline static char *AllocateEmptyPoolCharArray(size_t strLength)
{