Commit ce14ab97 authored by ishell@chromium.org's avatar ishell@chromium.org

HashTableKey::AsObject() handlified.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/250773004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20987 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc1fe284
......@@ -280,6 +280,75 @@ MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
}
Handle<String> Factory::NewInternalizedStringFromUtf8(Vector<const char> str,
int chars,
uint32_t hash_field) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateInternalizedStringFromUtf8(
str, chars, hash_field),
String);
}
MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedString(
Vector<const uint8_t> str,
uint32_t hash_field) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateOneByteInternalizedString(str, hash_field),
String);
}
MUST_USE_RESULT Handle<String> Factory::NewTwoByteInternalizedString(
Vector<const uc16> str,
uint32_t hash_field) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateTwoByteInternalizedString(str, hash_field),
String);
}
template<typename T>
Handle<String> Factory::NewInternalizedStringImpl(
T t, int chars, uint32_t hash_field) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateInternalizedStringImpl(t, chars, hash_field),
String);
}
template
Handle<String> Factory::NewInternalizedStringImpl(String*, int, uint32_t);
MaybeHandle<Map> Factory::InternalizedStringMapForString(
Handle<String> string) {
// If the string is in new space it cannot be used as internalized.
if (isolate()->heap()->InNewSpace(*string)) return MaybeHandle<Map>();
// Find the corresponding internalized string map for strings.
switch (string->map()->instance_type()) {
case STRING_TYPE: return internalized_string_map();
case ASCII_STRING_TYPE: return ascii_internalized_string_map();
case EXTERNAL_STRING_TYPE: return external_internalized_string_map();
case EXTERNAL_ASCII_STRING_TYPE:
return external_ascii_internalized_string_map();
case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
return external_internalized_string_with_one_byte_data_map();
case SHORT_EXTERNAL_STRING_TYPE:
return short_external_internalized_string_map();
case SHORT_EXTERNAL_ASCII_STRING_TYPE:
return short_external_ascii_internalized_string_map();
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
return short_external_internalized_string_with_one_byte_data_map();
default: return MaybeHandle<Map>(); // No match found.
}
}
MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
int length, PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
......
......@@ -145,6 +145,30 @@ class Factory V8_FINAL {
Vector<const uc16> str,
PretenureFlag pretenure = NOT_TENURED);
// Allocates an internalized string in old space based on the character
// stream.
MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8(
Vector<const char> str,
int chars,
uint32_t hash_field);
MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
Vector<const uint8_t> str,
uint32_t hash_field);
MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
Vector<const uc16> str,
uint32_t hash_field);
template<typename T>
MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
T t, int chars, uint32_t hash_field);
// Compute the matching internalized string map for a string if possible.
// Empty handle is returned if string is in new space or not flattened.
MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
Handle<String> string);
// Allocates and partially initializes an ASCII or TwoByte String. The
// characters of the string are uninitialized. Currently used in regexp code
// only, where they are pretenured.
......
......@@ -3997,30 +3997,6 @@ MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
}
Map* Heap::InternalizedStringMapForString(String* string) {
// If the string is in new space it cannot be used as internalized.
if (InNewSpace(string)) return NULL;
// Find the corresponding internalized string map for strings.
switch (string->map()->instance_type()) {
case STRING_TYPE: return internalized_string_map();
case ASCII_STRING_TYPE: return ascii_internalized_string_map();
case EXTERNAL_STRING_TYPE: return external_internalized_string_map();
case EXTERNAL_ASCII_STRING_TYPE:
return external_ascii_internalized_string_map();
case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
return external_internalized_string_with_one_byte_data_map();
case SHORT_EXTERNAL_STRING_TYPE:
return short_external_internalized_string_map();
case SHORT_EXTERNAL_ASCII_STRING_TYPE:
return short_external_ascii_internalized_string_map();
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
return short_external_internalized_string_with_one_byte_data_map();
default: return NULL; // No match found.
}
}
static inline void WriteOneByteData(Vector<const char> vector,
uint8_t* chars,
int len) {
......
......@@ -1003,10 +1003,6 @@ class Heap {
bool InternalizeStringIfExists(String* str, String** result);
bool InternalizeTwoCharsStringIfExists(String* str, String** result);
// Compute the matching internalized string map for a string if possible.
// NULL is returned if string is in new space or not flattened.
Map* InternalizedStringMapForString(String* str);
// Converts the given boolean condition to JavaScript boolean value.
inline Object* ToBoolean(bool condition);
......
......@@ -470,11 +470,6 @@ uc32 FlatStringReader::Get(int index) {
}
Handle<Object> HashTableKey::AsHandle(Isolate* isolate) {
CALL_HEAP_FUNCTION(isolate, AsObject(isolate->heap()), Object);
}
Handle<Object> StringTableShape::AsHandle(Isolate* isolate, HashTableKey* key) {
return key->AsHandle(isolate);
}
......@@ -532,7 +527,7 @@ class OneByteStringKey : public SequentialStringKey<uint8_t> {
return String::cast(string)->IsOneByteEqualTo(string_);
}
virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE;
virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE;
};
......@@ -563,7 +558,7 @@ class SubStringKey : public HashTableKey {
}
virtual bool IsMatch(Object* string) V8_OVERRIDE;
virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE;
virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE;
private:
const Char* GetChars();
......@@ -592,7 +587,7 @@ class TwoByteStringKey : public SequentialStringKey<uc16> {
return String::cast(string)->IsTwoByteEqualTo(string_);
}
virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE;
virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE;
};
......@@ -618,11 +613,10 @@ class Utf8StringKey : public HashTableKey {
return String::cast(other)->Hash();
}
virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE {
virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE {
if (hash_field_ == 0) Hash();
return heap->AllocateInternalizedStringFromUtf8(string_,
chars_,
hash_field_);
return isolate->factory()->NewInternalizedStringFromUtf8(
string_, chars_, hash_field_);
}
Vector<const char> string_;
......
This diff is collapsed.
......@@ -3634,7 +3634,7 @@ inline int Search(T* array, Name* name, int valid_entries = 0);
// // Returns the hash value for object.
// static uint32_t HashForObject(Key key, Object* object);
// // Convert key to an object.
// static inline Object* AsObject(Heap* heap, Key key);
// static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
// // The prefix size indicates number of elements in the beginning
// // of the backing storage.
// static const int kPrefixSize = ..;
......@@ -3852,10 +3852,7 @@ class HashTableKey {
// Returns the hash value for object.
virtual uint32_t HashForObject(Object* key) = 0;
// Returns the key object for storing into the hash table.
// If allocations fails a failure object is returned.
MUST_USE_RESULT virtual MaybeObject* AsObject(Heap* heap) = 0;
// TODO(ishell): This should eventually replace AsObject().
inline Handle<Object> AsHandle(Isolate* isolate);
MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0;
// Required.
virtual ~HashTableKey() {}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment