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

Side by Side Diff: src/heap-inl.h

Issue 11593007: Replace the use CharacterStreams in Heap::AllocateSymbolInternal and String::ComputeHash (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: issues addressed Created 8 years 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/heap.cc ('k') | src/json-parser.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (non_ascii_start >= length) { 91 if (non_ascii_start >= length) {
92 // If the string is ASCII, we do not need to convert the characters 92 // If the string is ASCII, we do not need to convert the characters
93 // since UTF8 is backwards compatible with ASCII. 93 // since UTF8 is backwards compatible with ASCII.
94 return AllocateStringFromOneByte(str, pretenure); 94 return AllocateStringFromOneByte(str, pretenure);
95 } 95 }
96 // Non-ASCII and we need to decode. 96 // Non-ASCII and we need to decode.
97 return AllocateStringFromUtf8Slow(str, non_ascii_start, pretenure); 97 return AllocateStringFromUtf8Slow(str, non_ascii_start, pretenure);
98 } 98 }
99 99
100 100
101 template<>
102 bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
103 // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
104 // ASCII only check.
105 return chars == str.length();
106 }
107
108
109 template<>
110 bool inline Heap::IsOneByte(String* str, int chars) {
111 return str->IsOneByteRepresentation();
112 }
113
114
101 MaybeObject* Heap::AllocateSymbol(Vector<const char> str, 115 MaybeObject* Heap::AllocateSymbol(Vector<const char> str,
102 int chars, 116 int chars,
103 uint32_t hash_field) { 117 uint32_t hash_field) {
104 unibrow::Utf8InputBuffer<> buffer(str.start(), 118 if (IsOneByte(str, chars)) return AllocateAsciiSymbol(str, hash_field);
105 static_cast<unsigned>(str.length())); 119 return AllocateInternalSymbol<false>(str, chars, hash_field);
106 return AllocateInternalSymbol(&buffer, chars, hash_field);
107 } 120 }
108 121
109 122
123 template<typename T>
124 MaybeObject* Heap::AllocateInternalSymbol(T t, int chars, uint32_t hash_field) {
125 if (IsOneByte(t, chars)) {
126 return AllocateInternalSymbol<true>(t, chars, hash_field);
127 }
128 return AllocateInternalSymbol<false>(t, chars, hash_field);
129 }
130
131
110 MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str, 132 MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str,
111 uint32_t hash_field) { 133 uint32_t hash_field) {
112 if (str.length() > SeqOneByteString::kMaxLength) { 134 if (str.length() > SeqOneByteString::kMaxLength) {
113 return Failure::OutOfMemoryException(); 135 return Failure::OutOfMemoryException();
114 } 136 }
115 // Compute map and object size. 137 // Compute map and object size.
116 Map* map = ascii_symbol_map(); 138 Map* map = ascii_symbol_map();
117 int size = SeqOneByteString::SizeFor(str.length()); 139 int size = SeqOneByteString::SizeFor(str.length());
118 140
119 // Allocate string. 141 // Allocate string.
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 AssertNoAllocation::~AssertNoAllocation() { } 839 AssertNoAllocation::~AssertNoAllocation() { }
818 DisableAssertNoAllocation::DisableAssertNoAllocation() { } 840 DisableAssertNoAllocation::DisableAssertNoAllocation() { }
819 DisableAssertNoAllocation::~DisableAssertNoAllocation() { } 841 DisableAssertNoAllocation::~DisableAssertNoAllocation() { }
820 842
821 #endif 843 #endif
822 844
823 845
824 } } // namespace v8::internal 846 } } // namespace v8::internal
825 847
826 #endif // V8_HEAP_INL_H_ 848 #endif // V8_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/json-parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698