Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: src/ast-value-factory.cc

Issue 1411103006: Make AstRawString deduplication encoding-agnostic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add test case Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-4450.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast-value-factory.cc
diff --git a/src/ast-value-factory.cc b/src/ast-value-factory.cc
index e790ea24469c9635589e27b6c7ca14b4ee760ddf..8a4a4daf0ce2b3218abaf262afc46dd2fc7d32ca 100644
--- a/src/ast-value-factory.cc
+++ b/src/ast-value-factory.cc
@@ -29,6 +29,7 @@
#include "src/api.h"
#include "src/objects.h"
+#include "src/utils.h"
namespace v8 {
namespace internal {
@@ -379,11 +380,32 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
bool AstValueFactory::AstRawStringCompare(void* a, void* b) {
const AstRawString* lhs = static_cast<AstRawString*>(a);
const AstRawString* rhs = static_cast<AstRawString*>(b);
- if (lhs->is_one_byte() != rhs->is_one_byte()) return false;
+ if (lhs->length() != rhs->length()) return false;
if (lhs->hash() != rhs->hash()) return false;
- int len = lhs->byte_length();
- if (rhs->byte_length() != len) return false;
- return memcmp(lhs->raw_data(), rhs->raw_data(), len) == 0;
+ const unsigned char* l = lhs->raw_data();
+ const unsigned char* r = rhs->raw_data();
+ size_t length = rhs->length();
+ if (lhs->is_one_byte()) {
+ if (rhs->is_one_byte()) {
+ return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
+ reinterpret_cast<const uint8_t*>(r),
+ length) == 0;
+ } else {
+ return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
+ reinterpret_cast<const uint16_t*>(r),
+ length) == 0;
+ }
+ } else {
+ if (rhs->is_one_byte()) {
+ return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
+ reinterpret_cast<const uint8_t*>(r),
+ length) == 0;
+ } else {
+ return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
+ reinterpret_cast<const uint16_t*>(r),
+ length) == 0;
+ }
+ }
}
} // namespace internal
} // namespace v8
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-4450.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698