| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2009 Google Inc. All rights reserved. | 2  * Copyright (C) 2009 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions | 5  * modification, are permitted provided that the following conditions | 
| 6  * are met: | 6  * are met: | 
| 7  * 1. Redistributions of source code must retain the above copyright | 7  * 1. Redistributions of source code must retain the above copyright | 
| 8  *    notice, this list of conditions and the following disclaimer. | 8  *    notice, this list of conditions and the following disclaimer. | 
| 9  * 2. Redistributions in binary form must reproduce the above copyright | 9  * 2. Redistributions in binary form must reproduce the above copyright | 
| 10  *    notice, this list of conditions and the following disclaimer in the | 10  *    notice, this list of conditions and the following disclaimer in the | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 40     static const String& fromStringResource(WebCoreStringResourceBase* resource) | 40     static const String& fromStringResource(WebCoreStringResourceBase* resource) | 
| 41     { | 41     { | 
| 42         return resource->webcoreString(); | 42         return resource->webcoreString(); | 
| 43     } | 43     } | 
| 44     template <typename V8StringTrait> | 44     template <typename V8StringTrait> | 
| 45     static String fromV8String(v8::Local<v8::String>, int); | 45     static String fromV8String(v8::Local<v8::String>, int); | 
| 46 }; | 46 }; | 
| 47 | 47 | 
| 48 template<> | 48 template<> | 
| 49 struct StringTraits<AtomicString> { | 49 struct StringTraits<AtomicString> { | 
| 50     static AtomicString fromStringResource(WebCoreStringResourceBase* resource) | 50     static const AtomicString& fromStringResource(WebCoreStringResourceBase* res
     ource) | 
| 51     { | 51     { | 
| 52         return resource->getAtomicString(); | 52         return resource->getAtomicString(); | 
| 53     } | 53     } | 
| 54     template <typename V8StringTrait> | 54     template <typename V8StringTrait> | 
| 55     static AtomicString fromV8String(v8::Local<v8::String>, int); | 55     static AtomicString fromV8String(v8::Local<v8::String>, int); | 
| 56 }; | 56 }; | 
| 57 | 57 | 
| 58 struct V8StringTwoBytesTrait { | 58 struct V8StringTwoBytesTrait { | 
| 59     typedef UChar CharType; | 59     typedef UChar CharType; | 
| 60     ALWAYS_INLINE static void write(v8::Local<v8::String> v8String, CharType* bu
     ffer, int length) | 60     ALWAYS_INLINE static void write(v8::Local<v8::String> v8String, CharType* bu
     ffer, int length) | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 99 | 99 | 
| 100 template<typename StringType> | 100 template<typename StringType> | 
| 101 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode 
     external) | 101 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode 
     external) | 
| 102 { | 102 { | 
| 103     { | 103     { | 
| 104         // This portion of this function is very hot in certain Dromeao benchmar
     ks. | 104         // This portion of this function is very hot in certain Dromeao benchmar
     ks. | 
| 105         v8::String::Encoding encoding; | 105         v8::String::Encoding encoding; | 
| 106         v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
     StringResourceBase(&encoding); | 106         v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
     StringResourceBase(&encoding); | 
| 107         if (LIKELY(!!resource)) { | 107         if (LIKELY(!!resource)) { | 
| 108             WebCoreStringResourceBase* base; | 108             WebCoreStringResourceBase* base; | 
| 109             if (UNLIKELY(resource->IsCompressible())) { | 109             if (encoding == v8::String::ONE_BYTE_ENCODING) | 
| 110                 if (encoding == v8::String::ONE_BYTE_ENCODING) | 110                 base = static_cast<WebCoreStringResource8*>(resource); | 
| 111                     base = static_cast<WebCoreCompressibleStringResource8*>(reso
     urce); | 111             else | 
| 112                 else | 112                 base = static_cast<WebCoreStringResource16*>(resource); | 
| 113                     base = static_cast<WebCoreCompressibleStringResource16*>(res
     ource); |  | 
| 114             } else { |  | 
| 115                 if (encoding == v8::String::ONE_BYTE_ENCODING) |  | 
| 116                     base = static_cast<WebCoreStringResource8*>(resource); |  | 
| 117                 else |  | 
| 118                     base = static_cast<WebCoreStringResource16*>(resource); |  | 
| 119             } |  | 
| 120             return StringTraits<StringType>::fromStringResource(base); | 113             return StringTraits<StringType>::fromStringResource(base); | 
| 121         } | 114         } | 
| 122     } | 115     } | 
| 123 | 116 | 
| 124     int length = v8String->Length(); | 117     int length = v8String->Length(); | 
| 125     if (UNLIKELY(!length)) | 118     if (UNLIKELY(!length)) | 
| 126         return StringType(""); | 119         return StringType(""); | 
| 127 | 120 | 
| 128     bool oneByte = v8String->ContainsOnlyOneByte(); | 121     bool oneByte = v8String->ContainsOnlyOneByte(); | 
| 129     StringType result(oneByte ? StringTraits<StringType>::template fromV8String<
     V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fro
     mV8String<V8StringTwoBytesTrait>(v8String, length)); | 122     StringType result(oneByte ? StringTraits<StringType>::template fromV8String<
     V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fro
     mV8String<V8StringTwoBytesTrait>(v8String, length)); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 174 | 167 | 
| 175 String int32ToWebCoreString(int value) | 168 String int32ToWebCoreString(int value) | 
| 176 { | 169 { | 
| 177     // If we are on the main thread (this should always true for non-workers), c
     all the faster one. | 170     // If we are on the main thread (this should always true for non-workers), c
     all the faster one. | 
| 178     if (isMainThread()) | 171     if (isMainThread()) | 
| 179         return int32ToWebCoreStringFast(value); | 172         return int32ToWebCoreStringFast(value); | 
| 180     return String::number(value); | 173     return String::number(value); | 
| 181 } | 174 } | 
| 182 | 175 | 
| 183 } // namespace blink | 176 } // namespace blink | 
| OLD | NEW | 
|---|