--- old/src/hotspot/share/oops/symbol.cpp 2019-04-24 13:36:21.000000000 -0700 +++ new/src/hotspot/share/oops/symbol.cpp 2019-04-24 13:36:21.000000000 -0700 @@ -74,14 +74,28 @@ } // ------------------------------------------------------------------ -// Symbol::starts_with +// Symbol::contains_byte_at // -// Tests if the symbol starts with the specified prefix of the given -// length. -bool Symbol::starts_with(const char* prefix, int len) const { - if (len > utf8_length()) return false; +// Tests if the symbol contains the given byte at the given position. +bool Symbol::contains_byte_at(int position, char code_byte) const { + if (position < 0) return false; // can happen with ends_with + if (position >= utf8_length()) return false; + return code_byte == char_at(position); +} + +// ------------------------------------------------------------------ +// Symbol::contains_utf8_at +// +// Tests if the symbol contains the given utf8 substring +// at the given byte position. +bool Symbol::contains_utf8_at(int position, const char* substring, int len) const { + assert(len > 0 && substring != NULL && (int) strlen(substring) >= len, + "substring must be valid"); + if (len == 1) return contains_byte_at(position, substring[0]); + if (position < 0) return false; // can happen with ends_with + if (position + len > utf8_length()) return false; while (len-- > 0) { - if (prefix[len] != char_at(len)) + if (substring[len] != char_at(position + len)) return false; } assert(len == -1, "we should be at the beginning"); @@ -89,11 +103,11 @@ } bool Symbol::is_Q_signature() const { - return utf8_length() > 2 && char_at(0) == 'Q' && char_at(utf8_length() - 1) == ';'; + return utf8_length() > 2 && char_at(0) == 'Q' && ends_with(';'); } Symbol* Symbol::fundamental_name(TRAPS) { - if ((char_at(0) == 'Q' || char_at(0) == 'L') && char_at(utf8_length() - 1) == ';') { + if ((char_at(0) == 'Q' || char_at(0) == 'L') && ends_with(';')) { return SymbolTable::lookup(this, 1, utf8_length() - 1, CHECK_NULL); } else { // reference count is incremented to be consistent with the behavior with @@ -107,7 +121,7 @@ if (this == s) return true; if (utf8_length() < 3) return false; int offset1, offset2, len; - if (char_at(utf8_length() - 1) == ';') { + if (ends_with(';')) { if (char_at(0) != 'Q' && char_at(0) != 'L') return false; offset1 = 1; len = utf8_length() - 2; @@ -115,7 +129,7 @@ offset1 = 0; len = utf8_length(); } - if (s->char_at(s->utf8_length() - 1) == ';') { + if (ends_with(';')) { if (s->char_at(0) != 'Q' && s->char_at(0) != 'L') return false; offset2 = 1; } else {