aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLString.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-09-07 15:44:01 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-11 16:17:00 +0000
commitc576e93d174f3106e072a2f506bca3990b541265 (patch)
treed4a410200aa71183c95643535b440bec919f2e18 /src/sksl/SkSLString.cpp
parenta2bdf005f3c706065d1aa93f319f4b73932721d4 (diff)
Switch to the new SkSL lexer.
This completely replaces flex with a new in-house lexical analyzer generator, which we have done for performance and memory usage reasons. Flex requires us to copy strings every time we need the text of a token, whereas this new lexer allows us to handle strings as a (non-null-terminated) pointer and length everywhere, eliminating most string copies. Bug: skia: Change-Id: I2add26efc9e20cb699520e82abcf713af3968aca Reviewed-on: https://skia-review.googlesource.com/39780 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLString.cpp')
-rw-r--r--src/sksl/SkSLString.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/sksl/SkSLString.cpp b/src/sksl/SkSLString.cpp
index ac6d7f85c1..5c53c43c72 100644
--- a/src/sksl/SkSLString.cpp
+++ b/src/sksl/SkSLString.cpp
@@ -77,6 +77,32 @@ String String::operator+(const String& s) const {
return result;
}
+String String::operator+(StringFragment s) const {
+ String result(*this);
+ result.append(s.fChars, s.fLength);
+ return result;
+}
+
+String& String::operator+=(char c) {
+ INHERITED::operator+=(c);
+ return *this;
+}
+
+String& String::operator+=(const char* s) {
+ INHERITED::operator+=(s);
+ return *this;
+}
+
+String& String::operator+=(const String& s) {
+ INHERITED::operator+=(s);
+ return *this;
+}
+
+String& String::operator+=(StringFragment s) {
+ this->append(s.fChars, s.fLength);
+ return *this;
+}
+
bool String::operator==(const String& s) const {
return this->size() == s.size() && !memcmp(c_str(), s.c_str(), this->size());
}
@@ -107,6 +133,28 @@ bool operator!=(const char* s1, const String& s2) {
return s2 != s1;
}
+bool StringFragment::operator==(StringFragment s) const {
+ if (fLength != s.fLength) {
+ return false;
+ }
+ return !memcmp(fChars, s.fChars, fLength);
+}
+
+bool StringFragment::operator!=(StringFragment s) const {
+ if (fLength != s.fLength) {
+ return true;
+ }
+ return memcmp(fChars, s.fChars, fLength);
+}
+
+bool StringFragment::operator==(const char* s) const {
+ return !memcmp(fChars, s, fLength);
+}
+
+bool StringFragment::operator!=(const char* s) const {
+ return memcmp(fChars, s, fLength);
+}
+
String to_string(int32_t value) {
return SkSL::String::printf("%d", value);
}