Commit 84ae8d31 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Remove some unnecessary use of templates.

R=dcarney@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/11958040

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13413 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a496e0d0
......@@ -4181,43 +4181,41 @@ int String::WriteAscii(char* buffer,
template<typename CharType>
struct WriteHelper {
static inline int Write(const String* string,
CharType* buffer,
int start,
int length,
int options) {
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
LOG_API(isolate, "String::Write");
ENTER_V8(isolate);
ASSERT(start >= 0 && length >= -1);
i::Handle<i::String> str = Utils::OpenHandle(string);
isolate->string_tracker()->RecordWrite(str);
if (options & String::HINT_MANY_WRITES_EXPECTED) {
// Flatten the string for efficiency. This applies whether we are
// using StringCharacterStream or Get(i) to access the characters.
FlattenString(str);
}
int end = start + length;
if ((length == -1) || (length > str->length() - start) )
end = str->length();
if (end < 0) return 0;
i::String::WriteToFlat(*str, buffer, start, end);
if (!(options & String::NO_NULL_TERMINATION) &&
(length == -1 || end - start < length)) {
buffer[end - start] = '\0';
}
return end - start;
static inline int WriteHelper(const String* string,
CharType* buffer,
int start,
int length,
int options) {
i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
LOG_API(isolate, "String::Write");
ENTER_V8(isolate);
ASSERT(start >= 0 && length >= -1);
i::Handle<i::String> str = Utils::OpenHandle(string);
isolate->string_tracker()->RecordWrite(str);
if (options & String::HINT_MANY_WRITES_EXPECTED) {
// Flatten the string for efficiency. This applies whether we are
// using StringCharacterStream or Get(i) to access the characters.
FlattenString(str);
}
int end = start + length;
if ((length == -1) || (length > str->length() - start) )
end = str->length();
if (end < 0) return 0;
i::String::WriteToFlat(*str, buffer, start, end);
if (!(options & String::NO_NULL_TERMINATION) &&
(length == -1 || end - start < length)) {
buffer[end - start] = '\0';
}
};
return end - start;
}
int String::WriteOneByte(uint8_t* buffer,
int start,
int length,
int options) const {
return WriteHelper<uint8_t>::Write(this, buffer, start, length, options);
return WriteHelper(this, buffer, start, length, options);
}
......@@ -4225,7 +4223,7 @@ int String::Write(uint16_t* buffer,
int start,
int length,
int options) const {
return WriteHelper<uint16_t>::Write(this, buffer, start, length, options);
return WriteHelper(this, buffer, start, length, options);
}
......
......@@ -4674,82 +4674,57 @@ Map* Heap::SymbolMapForString(String* string) {
}
template<typename T>
class AllocateInternalSymbolHelper {
public:
static void WriteOneByteData(T t, char* chars, int len);
static void WriteTwoByteData(T t, uint16_t* chars, int len);
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
};
template<>
class AllocateInternalSymbolHelper< Vector<const char> > {
public:
static inline void WriteOneByteData(Vector<const char> vector,
uint8_t* chars,
int len) {
// Only works for ascii.
ASSERT(vector.length() == len);
memcpy(chars, vector.start(), len);
}
static inline void WriteTwoByteData(Vector<const char> vector,
uint16_t* chars,
int len) {
const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start());
unsigned stream_length = vector.length();
while (stream_length != 0) {
unsigned consumed = 0;
uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed);
ASSERT(c != unibrow::Utf8::kBadChar);
ASSERT(consumed <= stream_length);
stream_length -= consumed;
stream += consumed;
if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) {
len -= 2;
if (len < 0) break;
*chars++ = unibrow::Utf16::LeadSurrogate(c);
*chars++ = unibrow::Utf16::TrailSurrogate(c);
} else {
len -= 1;
if (len < 0) break;
*chars++ = c;
}
static inline void WriteOneByteData(Vector<const char> vector,
uint8_t* chars,
int len) {
// Only works for ascii.
ASSERT(vector.length() == len);
memcpy(chars, vector.start(), len);
}
static inline void WriteTwoByteData(Vector<const char> vector,
uint16_t* chars,
int len) {
const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start());
unsigned stream_length = vector.length();
while (stream_length != 0) {
unsigned consumed = 0;
uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed);
ASSERT(c != unibrow::Utf8::kBadChar);
ASSERT(consumed <= stream_length);
stream_length -= consumed;
stream += consumed;
if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) {
len -= 2;
if (len < 0) break;
*chars++ = unibrow::Utf16::LeadSurrogate(c);
*chars++ = unibrow::Utf16::TrailSurrogate(c);
} else {
len -= 1;
if (len < 0) break;
*chars++ = c;
}
ASSERT(stream_length == 0);
ASSERT(len == 0);
}
ASSERT(stream_length == 0);
ASSERT(len == 0);
}
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
};
template<>
class AllocateInternalSymbolHelper<String*> {
public:
static inline void WriteOneByteData(String* s, uint8_t* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
static inline void WriteOneByteData(String* s, uint8_t* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper<String*>);
};
static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
template<bool is_one_byte, typename T>
MaybeObject* Heap::AllocateInternalSymbol(T t,
int chars,
uint32_t hash_field) {
typedef AllocateInternalSymbolHelper<T> H;
ASSERT(chars >= 0);
// Compute map and object size.
int size;
......@@ -4786,9 +4761,9 @@ MaybeObject* Heap::AllocateInternalSymbol(T t,
ASSERT_EQ(size, answer->Size());
if (is_one_byte) {
H::WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars);
WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars);
} else {
H::WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars);
WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars);
}
return answer;
}
......
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