Changeset 132169 in webkit
- Timestamp:
- Oct 22, 2012 5:58:14 PM (12 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r132161 r132169 1 2012-10-22 Anders Carlsson <andersca@apple.com> 2 3 Handle ArgumentCoder template specializations that take the ArgumentEncoder as a reference 4 https://bugs.webkit.org/show_bug.cgi?id=100056 5 6 Reviewed by Andreas Kling. 7 8 Use template magic to make it possible to have ArgumentCoder specializations where the encode 9 function takes the ArgumentEncoder object as a reference instead of as a pointer. Also, add an 10 operator<< to ArgumentEncoder and change the string related ArgumentCoder specializations over to taking 11 the encoder as a reference and using stream operators. 12 13 * Platform/CoreIPC/ArgumentCoders.cpp: 14 (CoreIPC::::encode): 15 * Platform/CoreIPC/ArgumentCoders.h: 16 * Platform/CoreIPC/ArgumentEncoder.h: 17 (ArgumentEncoder): 18 (UsesDeprecatedEncodeFunction): 19 (NoType): 20 (CoreIPC::ArgumentEncoder::encode): 21 (CoreIPC::ArgumentEncoder::operator<<): 22 1 23 2012-10-22 Anders Carlsson <andersca@apple.com> 2 24 -
trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.cpp
r131990 r132169 27 27 #include "ArgumentCoders.h" 28 28 29 #include "DataReference.h" 29 30 #include <wtf/text/CString.h> 30 31 #include <wtf/text/WTFString.h> … … 32 33 namespace CoreIPC { 33 34 34 void ArgumentCoder<AtomicString>::encode(ArgumentEncoder *encoder, const AtomicString& atomicString)35 void ArgumentCoder<AtomicString>::encode(ArgumentEncoder& encoder, const AtomicString& atomicString) 35 36 { 36 encoder ->encode(atomicString.string());37 encoder << atomicString.string(); 37 38 } 38 39 … … 47 48 } 48 49 49 void ArgumentCoder<CString>::encode(ArgumentEncoder *encoder, const CString& string)50 void ArgumentCoder<CString>::encode(ArgumentEncoder& encoder, const CString& string) 50 51 { 51 52 // Special case the null string. 52 53 if (string.isNull()) { 53 encoder ->encode(std::numeric_limits<uint32_t>::max());54 encoder << std::numeric_limits<uint32_t>::max(); 54 55 return; 55 56 } 56 57 57 58 uint32_t length = string.length(); 58 encoder->encode(length); 59 encoder->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length, 1); 59 encoder << length << CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(string.data()), length); 60 60 } 61 61 … … 88 88 89 89 90 void ArgumentCoder<String>::encode(ArgumentEncoder *encoder, const String& string)90 void ArgumentCoder<String>::encode(ArgumentEncoder& encoder, const String& string) 91 91 { 92 92 // Special case the null string. 93 93 if (string.isNull()) { 94 encoder ->encode(std::numeric_limits<uint32_t>::max());94 encoder << std::numeric_limits<uint32_t>::max(); 95 95 return; 96 96 } 97 97 98 98 uint32_t length = string.length(); 99 encoder->encode(length);100 99 bool is8Bit = string.is8Bit(); 101 encoder->encode(is8Bit); 100 101 encoder << length << is8Bit; 102 102 103 if (is8Bit) 103 encoder ->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), __alignof(LChar));104 encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), __alignof(LChar)); 104 105 else 105 encoder ->encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), __alignof(UChar));106 encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), __alignof(UChar)); 106 107 } 107 108 -
trunk/Source/WebKit2/Platform/CoreIPC/ArgumentCoders.h
r132161 r132169 198 198 199 199 template<> struct ArgumentCoder<AtomicString> { 200 static void encode(ArgumentEncoder *, const AtomicString&);200 static void encode(ArgumentEncoder&, const AtomicString&); 201 201 static bool decode(ArgumentDecoder*, AtomicString&); 202 202 }; 203 203 204 204 template<> struct ArgumentCoder<CString> { 205 static void encode(ArgumentEncoder *, const CString&);205 static void encode(ArgumentEncoder&, const CString&); 206 206 static bool decode(ArgumentDecoder*, CString&); 207 207 }; 208 208 209 209 template<> struct ArgumentCoder<String> { 210 static void encode(ArgumentEncoder *, const String&);210 static void encode(ArgumentEncoder&, const String&); 211 211 static bool decode(ArgumentDecoder*, String&); 212 212 }; -
trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h
r131990 r132169 61 61 encode(static_cast<uint64_t>(t)); 62 62 } 63 64 template<bool B, typename T = void> 65 struct EnableIf { }; 66 67 template<typename T> 68 struct EnableIf<true, T> { typedef T Type; }; 63 69 64 // Generic type encode function. 65 template<typename T> void encode(const T& t) 70 template<typename T> class UsesDeprecatedEncodeFunction { 71 typedef char YesType; 72 struct NoType { 73 char padding[8]; 74 }; 75 76 static YesType checkEncode(void (*)(ArgumentEncoder*, const T&)); 77 static NoType checkEncode(...); 78 79 public: 80 static const bool value = sizeof(checkEncode(ArgumentCoder<T>::encode)) == sizeof(YesType); 81 }; 82 83 // FIXME: This is the function that gets chosen if the argument coder takes the ArgumentEncoder as a pointer. 84 // This is the deprecated form - get rid of it. 85 template<typename T> void encode(const T& t, typename EnableIf<UsesDeprecatedEncodeFunction<T>::value>::Type* = 0) 66 86 { 67 87 ArgumentCoder<T>::encode(this, t); 88 } 89 90 template<typename T> void encode(const T& t, typename EnableIf<!UsesDeprecatedEncodeFunction<T>::value>::Type* = 0) 91 { 92 ArgumentCoder<T>::encode(*this, t); 93 } 94 95 template<typename T> ArgumentEncoder& operator<<(const T& t) 96 { 97 encode(t); 98 return *this; 68 99 } 69 100
Note: See TracChangeset
for help on using the changeset viewer.