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

Side by Side Diff: src/objects.cc

Issue 143223004: Generalize internalization of substrings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add handling of sliced substrings Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 13972 matching lines...) Expand 10 before | Expand all | Expand 10 after
13983 Smi* flags_; 13983 Smi* flags_;
13984 }; 13984 };
13985 13985
13986 13986
13987 MaybeObject* OneByteStringKey::AsObject(Heap* heap) { 13987 MaybeObject* OneByteStringKey::AsObject(Heap* heap) {
13988 if (hash_field_ == 0) Hash(); 13988 if (hash_field_ == 0) Hash();
13989 return heap->AllocateOneByteInternalizedString(string_, hash_field_); 13989 return heap->AllocateOneByteInternalizedString(string_, hash_field_);
13990 } 13990 }
13991 13991
13992 13992
13993 MaybeObject* SubStringOneByteStringKey::AsObject(Heap* heap) {
13994 if (hash_field_ == 0) Hash();
13995 Vector<const uint8_t> chars(string_->GetChars() + from_, length_);
13996 return heap->AllocateOneByteInternalizedString(chars, hash_field_);
13997 }
13998
13999
14000 MaybeObject* TwoByteStringKey::AsObject(Heap* heap) { 13993 MaybeObject* TwoByteStringKey::AsObject(Heap* heap) {
14001 if (hash_field_ == 0) Hash(); 13994 if (hash_field_ == 0) Hash();
14002 return heap->AllocateTwoByteInternalizedString(string_, hash_field_); 13995 return heap->AllocateTwoByteInternalizedString(string_, hash_field_);
14003 } 13996 }
14004 13997
14005 13998
13999 template<>
14000 const uint8_t* SubStringKey<uint8_t>::GetChars() {
14001 return string_->IsSeqOneByteString()
14002 ? SeqOneByteString::cast(*string_)->GetChars()
14003 : ExternalAsciiString::cast(*string_)->GetChars();
14004 }
14005
14006
14007 template<>
14008 const uint16_t* SubStringKey<uint16_t>::GetChars() {
14009 return string_->IsSeqTwoByteString()
14010 ? SeqTwoByteString::cast(*string_)->GetChars()
14011 : ExternalTwoByteString::cast(*string_)->GetChars();
14012 }
14013
14014
14015 template<>
14016 MaybeObject* SubStringKey<uint8_t>::AsObject(Heap* heap) {
14017 if (hash_field_ == 0) Hash();
14018 Vector<const uint8_t> chars(GetChars() + from_, length_);
14019 return heap->AllocateOneByteInternalizedString(chars, hash_field_);
14020 }
14021
14022
14023 template<>
14024 MaybeObject* SubStringKey<uint16_t>::AsObject(
14025 Heap* heap) {
14026 if (hash_field_ == 0) Hash();
14027 Vector<const uint16_t> chars(GetChars() + from_, length_);
14028 return heap->AllocateTwoByteInternalizedString(chars, hash_field_);
14029 }
14030
14031
14032 template<>
14033 bool SubStringKey<uint8_t>::IsMatch(Object* string) {
14034 Vector<const uint8_t> chars(GetChars() + from_, length_);
14035 return String::cast(string)->IsOneByteEqualTo(chars);
14036 }
14037
14038
14039 template<>
14040 bool SubStringKey<uint16_t>::IsMatch(Object* string) {
14041 Vector<const uint16_t> chars(GetChars() + from_, length_);
14042 return String::cast(string)->IsTwoByteEqualTo(chars);
14043 }
14044
14045
14046 template class SubStringKey<uint8_t>;
14047 template class SubStringKey<uint16_t>;
14048
14049
14006 // InternalizedStringKey carries a string/internalized-string object as key. 14050 // InternalizedStringKey carries a string/internalized-string object as key.
14007 class InternalizedStringKey : public HashTableKey { 14051 class InternalizedStringKey : public HashTableKey {
14008 public: 14052 public:
14009 explicit InternalizedStringKey(String* string) 14053 explicit InternalizedStringKey(String* string)
14010 : string_(string) { } 14054 : string_(string) { }
14011 14055
14012 bool IsMatch(Object* string) { 14056 bool IsMatch(Object* string) {
14013 return String::cast(string)->Equals(string_); 14057 return String::cast(string)->Equals(string_);
14014 } 14058 }
14015 14059
(...skipping 2578 matching lines...) Expand 10 before | Expand all | Expand 10 after
16594 #define ERROR_MESSAGES_TEXTS(C, T) T, 16638 #define ERROR_MESSAGES_TEXTS(C, T) T,
16595 static const char* error_messages_[] = { 16639 static const char* error_messages_[] = {
16596 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16640 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16597 }; 16641 };
16598 #undef ERROR_MESSAGES_TEXTS 16642 #undef ERROR_MESSAGES_TEXTS
16599 return error_messages_[reason]; 16643 return error_messages_[reason];
16600 } 16644 }
16601 16645
16602 16646
16603 } } // namespace v8::internal 16647 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698