Changeset 221384 in webkit
- Timestamp:
- Aug 30, 2017 10:46:55 AM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 3 added
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r221358 r221384 1 2017-08-22 Filip Pizlo <fpizlo@apple.com> 2 3 Strings need to be in some kind of gigacage 4 https://bugs.webkit.org/show_bug.cgi?id=174924 5 6 Reviewed by Oliver Hunt. 7 8 * runtime/JSString.cpp: 9 (JSC::JSRopeString::resolveRopeToAtomicString const): 10 (JSC::JSRopeString::resolveRope const): 11 * runtime/JSString.h: 12 (JSC::JSString::create): 13 (JSC::JSString::createHasOtherOwner): 14 * runtime/JSStringBuilder.h: 15 * runtime/VM.h: 16 (JSC::VM::gigacageAuxiliarySpace): 17 1 18 2017-08-30 Oleksandr Skachkov <gskachkov@gmail.com> 2 19 -
trunk/Source/JavaScriptCore/runtime/JSString.cpp
r217108 r221384 179 179 void JSRopeString::resolveRopeToAtomicString(ExecState* exec) const 180 180 { 181 if (length() > maxLengthForOnStackResolve) { 182 resolveRope(exec); 183 m_value = AtomicString(m_value); 184 setIs8Bit(m_value.impl()->is8Bit()); 185 return; 186 } 187 188 if (is8Bit()) { 189 LChar buffer[maxLengthForOnStackResolve]; 190 resolveRopeInternal8(buffer); 191 m_value = AtomicString(buffer, length()); 192 setIs8Bit(m_value.impl()->is8Bit()); 193 } else { 194 UChar buffer[maxLengthForOnStackResolve]; 195 resolveRopeInternal16(buffer); 196 m_value = AtomicString(buffer, length()); 197 setIs8Bit(m_value.impl()->is8Bit()); 198 } 199 200 clearFibers(); 201 202 // If we resolved a string that didn't previously exist, notify the heap that we've grown. 203 if (m_value.impl()->hasOneRef()) 204 Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost()); 181 [&] () { 182 if (length() > maxLengthForOnStackResolve) { 183 resolveRope(exec); 184 m_value = AtomicString(m_value); 185 setIs8Bit(m_value.impl()->is8Bit()); 186 return; 187 } 188 189 if (is8Bit()) { 190 LChar buffer[maxLengthForOnStackResolve]; 191 resolveRopeInternal8(buffer); 192 m_value = AtomicString(buffer, length()); 193 setIs8Bit(m_value.impl()->is8Bit()); 194 } else { 195 UChar buffer[maxLengthForOnStackResolve]; 196 resolveRopeInternal16(buffer); 197 m_value = AtomicString(buffer, length()); 198 setIs8Bit(m_value.impl()->is8Bit()); 199 } 200 201 clearFibers(); 202 203 // If we resolved a string that didn't previously exist, notify the heap that we've grown. 204 if (m_value.impl()->hasOneRef()) 205 Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost()); 206 }(); 207 208 m_value.releaseAssertCaged(); 205 209 } 206 210 … … 249 253 void JSRopeString::resolveRope(ExecState* exec) const 250 254 { 251 ASSERT(isRope()); 252 253 if (isSubstring()) { 254 ASSERT(!substringBase()->isRope()); 255 m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length()); 256 substringBase().clear(); 257 return; 258 } 259 260 if (is8Bit()) { 261 LChar* buffer; 255 [&] () { 256 ASSERT(isRope()); 257 258 if (isSubstring()) { 259 ASSERT(!substringBase()->isRope()); 260 m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length()); 261 substringBase().clear(); 262 return; 263 } 264 265 if (is8Bit()) { 266 LChar* buffer; 267 if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) { 268 Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost()); 269 m_value = WTFMove(newImpl); 270 } else { 271 outOfMemory(exec); 272 return; 273 } 274 resolveRopeInternal8NoSubstring(buffer); 275 clearFibers(); 276 ASSERT(!isRope()); 277 return; 278 } 279 280 UChar* buffer; 262 281 if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) { 263 282 Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost()); … … 267 286 return; 268 287 } 269 resolveRopeInternal8NoSubstring(buffer); 288 289 resolveRopeInternal16NoSubstring(buffer); 270 290 clearFibers(); 271 291 ASSERT(!isRope()); 272 return; 273 } 274 275 UChar* buffer; 276 if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) { 277 Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost()); 278 m_value = WTFMove(newImpl); 279 } else { 280 outOfMemory(exec); 281 return; 282 } 283 284 resolveRopeInternal16NoSubstring(buffer); 285 clearFibers(); 286 ASSERT(!isRope()); 292 }(); 293 294 m_value.releaseAssertCaged(); 287 295 } 288 296 -
trunk/Source/JavaScriptCore/runtime/JSString.h
r221192 r221384 140 140 static JSString* create(VM& vm, Ref<StringImpl>&& value) 141 141 { 142 value->assertCaged(); 142 143 unsigned length = value->length(); 143 144 size_t cost = value->cost(); … … 148 149 static JSString* createHasOtherOwner(VM& vm, Ref<StringImpl>&& value) 149 150 { 151 value->assertCaged(); 150 152 size_t length = value->length(); 151 153 JSString* newString = new (NotNull, allocateCell<JSString>(vm.heap)) JSString(vm, WTFMove(value)); -
trunk/Source/JavaScriptCore/runtime/JSStringBuilder.h
r221192 r221384 1 1 /* 2 * Copyright (C) 2009 , 2016Apple Inc. All rights reserved.2 * Copyright (C) 2009-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #include "ExceptionHelpers.h" 29 29 #include "JSString.h" 30 #include <wtf/ Vector.h>30 #include <wtf/text/StringVector.h> 31 31 32 32 namespace JSC { … … 114 114 } 115 115 116 Vector<LChar, 64, UnsafeVectorOverflow> buffer8;117 Vector<UChar, 64, UnsafeVectorOverflow> buffer16;116 StringVector<LChar, 64, UnsafeVectorOverflow> buffer8; 117 StringVector<UChar, 64, UnsafeVectorOverflow> buffer16; 118 118 bool m_okay; 119 119 bool m_is8Bit; -
trunk/Source/JavaScriptCore/runtime/VM.h
r221223 r221384 309 309 case Gigacage::JSValue: 310 310 return jsValueGigacageAuxiliarySpace; 311 case Gigacage::String: 312 break; 311 313 } 312 314 RELEASE_ASSERT_NOT_REACHED(); -
trunk/Source/WTF/ChangeLog
r221330 r221384 1 2017-08-22 Filip Pizlo <fpizlo@apple.com> 2 3 Strings need to be in some kind of gigacage 4 https://bugs.webkit.org/show_bug.cgi?id=174924 5 6 Reviewed by Oliver Hunt. 7 8 This makes all strings allocations come from the string gigacage. Because we expect string allocation 9 to be a hot path, I created specialized allocation paths for the string gigacage. These paths are 10 accessible via <wtf/text/StringMalloc.h>. However, those paths are equivalent to saying 11 Gigacage::malloc and friends with the Gigacage::String kind. 12 13 * WTF.xcodeproj/project.pbxproj: 14 * wtf/CMakeLists.txt: 15 * wtf/Deque.h: 16 * wtf/FastMalloc.cpp: 17 (WTF::fastFree): 18 * wtf/FastMalloc.h: 19 (WTF::FastMalloc::malloc): 20 (WTF::FastMalloc::tryMalloc): 21 (WTF::FastMalloc::realloc): 22 (WTF::FastMalloc::free): 23 * wtf/Forward.h: 24 * wtf/Gigacage.cpp: 25 (Gigacage::tryMalloc): 26 * wtf/Gigacage.h: 27 (Gigacage::name): 28 * wtf/Vector.h: 29 (WTF::VectorBufferBase::allocateBuffer): 30 (WTF::VectorBufferBase::tryAllocateBuffer): 31 (WTF::VectorBufferBase::reallocateBuffer): 32 (WTF::VectorBufferBase::deallocateBuffer): 33 (WTF::Malloc>::Vector): 34 (WTF::=): 35 (WTF::Malloc>::contains const): 36 (WTF::Malloc>::findMatching const): 37 (WTF::Malloc>::find const): 38 (WTF::Malloc>::reverseFind const): 39 (WTF::Malloc>::appendIfNotContains): 40 (WTF::Malloc>::fill): 41 (WTF::Malloc>::appendRange): 42 (WTF::Malloc>::expandCapacity): 43 (WTF::Malloc>::tryExpandCapacity): 44 (WTF::Malloc>::resize): 45 (WTF::Malloc>::resizeToFit): 46 (WTF::Malloc>::shrink): 47 (WTF::Malloc>::grow): 48 (WTF::Malloc>::asanSetInitialBufferSizeTo): 49 (WTF::Malloc>::asanSetBufferSizeToFullCapacity): 50 (WTF::Malloc>::asanBufferSizeWillChangeTo): 51 (WTF::Malloc>::reserveCapacity): 52 (WTF::Malloc>::tryReserveCapacity): 53 (WTF::Malloc>::reserveInitialCapacity): 54 (WTF::Malloc>::shrinkCapacity): 55 (WTF::Malloc>::append): 56 (WTF::Malloc>::tryAppend): 57 (WTF::Malloc>::constructAndAppend): 58 (WTF::Malloc>::tryConstructAndAppend): 59 (WTF::Malloc>::appendSlowCase): 60 (WTF::Malloc>::constructAndAppendSlowCase): 61 (WTF::Malloc>::tryConstructAndAppendSlowCase): 62 (WTF::Malloc>::uncheckedAppend): 63 (WTF::Malloc>::appendVector): 64 (WTF::Malloc>::insert): 65 (WTF::Malloc>::insertVector): 66 (WTF::Malloc>::remove): 67 (WTF::Malloc>::removeFirst): 68 (WTF::Malloc>::removeFirstMatching): 69 (WTF::Malloc>::removeAll): 70 (WTF::Malloc>::removeAllMatching): 71 (WTF::Malloc>::reverse): 72 (WTF::Malloc>::map const): 73 (WTF::Malloc>::releaseBuffer): 74 (WTF::Malloc>::checkConsistency): 75 (WTF::swap): 76 (WTF::operator==): 77 (WTF::operator!=): 78 (WTF::removeRepeatedElements): 79 (WTF::minCapacity>::Vector): Deleted. 80 (WTF::minCapacity>::contains const): Deleted. 81 (WTF::minCapacity>::findMatching const): Deleted. 82 (WTF::minCapacity>::find const): Deleted. 83 (WTF::minCapacity>::reverseFind const): Deleted. 84 (WTF::minCapacity>::appendIfNotContains): Deleted. 85 (WTF::minCapacity>::fill): Deleted. 86 (WTF::minCapacity>::appendRange): Deleted. 87 (WTF::minCapacity>::expandCapacity): Deleted. 88 (WTF::minCapacity>::tryExpandCapacity): Deleted. 89 (WTF::minCapacity>::resize): Deleted. 90 (WTF::minCapacity>::resizeToFit): Deleted. 91 (WTF::minCapacity>::shrink): Deleted. 92 (WTF::minCapacity>::grow): Deleted. 93 (WTF::minCapacity>::asanSetInitialBufferSizeTo): Deleted. 94 (WTF::minCapacity>::asanSetBufferSizeToFullCapacity): Deleted. 95 (WTF::minCapacity>::asanBufferSizeWillChangeTo): Deleted. 96 (WTF::minCapacity>::reserveCapacity): Deleted. 97 (WTF::minCapacity>::tryReserveCapacity): Deleted. 98 (WTF::minCapacity>::reserveInitialCapacity): Deleted. 99 (WTF::minCapacity>::shrinkCapacity): Deleted. 100 (WTF::minCapacity>::append): Deleted. 101 (WTF::minCapacity>::tryAppend): Deleted. 102 (WTF::minCapacity>::constructAndAppend): Deleted. 103 (WTF::minCapacity>::tryConstructAndAppend): Deleted. 104 (WTF::minCapacity>::appendSlowCase): Deleted. 105 (WTF::minCapacity>::constructAndAppendSlowCase): Deleted. 106 (WTF::minCapacity>::tryConstructAndAppendSlowCase): Deleted. 107 (WTF::minCapacity>::uncheckedAppend): Deleted. 108 (WTF::minCapacity>::appendVector): Deleted. 109 (WTF::minCapacity>::insert): Deleted. 110 (WTF::minCapacity>::insertVector): Deleted. 111 (WTF::minCapacity>::remove): Deleted. 112 (WTF::minCapacity>::removeFirst): Deleted. 113 (WTF::minCapacity>::removeFirstMatching): Deleted. 114 (WTF::minCapacity>::removeAll): Deleted. 115 (WTF::minCapacity>::removeAllMatching): Deleted. 116 (WTF::minCapacity>::reverse): Deleted. 117 (WTF::minCapacity>::map const): Deleted. 118 (WTF::minCapacity>::releaseBuffer): Deleted. 119 (WTF::minCapacity>::checkConsistency): Deleted. 120 * wtf/text/AtomicStringImpl.h: 121 * wtf/text/CString.cpp: 122 (WTF::CStringBuffer::createUninitialized): 123 * wtf/text/CString.h: 124 * wtf/text/StringBuffer.h: 125 (WTF::StringBuffer::StringBuffer): 126 (WTF::StringBuffer::~StringBuffer): 127 (WTF::StringBuffer::resize): 128 * wtf/text/StringImpl.cpp: 129 (WTF::StringImpl::~StringImpl): 130 (WTF::StringImpl::destroy): 131 (WTF::StringImpl::createUninitializedInternalNonEmpty): 132 (WTF::StringImpl::reallocateInternal): 133 (WTF::StringImpl::releaseAssertCaged const): 134 * wtf/text/StringImpl.h: 135 (WTF::StringImpl::createSubstringSharingImpl): 136 (WTF::StringImpl::tryCreateUninitialized): 137 (WTF::StringImpl::adopt): 138 (WTF::StringImpl::bufferOwnership const): 139 (WTF::StringImpl::assertCaged const): 140 * wtf/text/StringMalloc.cpp: Added. 141 (WTF::tryStringMalloc): 142 (WTF::stringMalloc): 143 (WTF::stringRealloc): 144 (WTF::stringFree): 145 * wtf/text/StringMalloc.h: Added. 146 (WTF::StringMalloc::malloc): 147 (WTF::StringMalloc::tryMalloc): 148 (WTF::StringMalloc::realloc): 149 (WTF::StringMalloc::free): 150 * wtf/text/StringVector.h: Added. 151 * wtf/text/SymbolImpl.h: 152 * wtf/text/UniquedStringImpl.h: 153 * wtf/text/WTFString.h: 154 (WTF::String::adopt): 155 (WTF::String::assertCaged const): 156 (WTF::String::releaseAssertCaged const): 157 1 158 2017-08-28 Yusuke Suzuki <utatane.tea@gmail.com> 2 159 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r221330 r221384 22 22 23 23 /* Begin PBXBuildFile section */ 24 0F0F526B1F421FF8004A452C /* StringMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F52691F421FF8004A452C /* StringMalloc.cpp */; }; 24 25 0F30BA901E78708E002CA847 /* GlobalVersion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F30BA8A1E78708E002CA847 /* GlobalVersion.cpp */; }; 25 26 0F43D8F11DB5ADDC00108FB6 /* AutomaticThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F43D8EF1DB5ADDC00108FB6 /* AutomaticThread.cpp */; }; … … 164 165 /* Begin PBXFileReference section */ 165 166 0F0D85B317234CB100338210 /* NoLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoLock.h; sourceTree = "<group>"; }; 167 0F0F52691F421FF8004A452C /* StringMalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringMalloc.cpp; sourceTree = "<group>"; }; 168 0F0F526A1F421FF8004A452C /* StringMalloc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StringMalloc.h; sourceTree = "<group>"; }; 166 169 0F0FCDDD1DD167F900CCAB53 /* LockAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LockAlgorithm.h; sourceTree = "<group>"; }; 167 170 0F2AC5601E89F70C0001EE3F /* Range.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Range.h; sourceTree = "<group>"; }; … … 177 180 0F30BA8F1E78708E002CA847 /* LoggingHashTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggingHashTraits.h; sourceTree = "<group>"; }; 178 181 0F31DD701F1308BC0072EB4A /* LockAlgorithmInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LockAlgorithmInlines.h; sourceTree = "<group>"; }; 182 0F348C7D1F47AA9D003CFEF2 /* StringVector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StringVector.h; sourceTree = "<group>"; }; 179 183 0F3501631BB258C800F0A2A3 /* WeakRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakRandom.h; sourceTree = "<group>"; }; 180 184 0F43D8EF1DB5ADDC00108FB6 /* AutomaticThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomaticThread.cpp; sourceTree = "<group>"; }; … … 1089 1093 A8A47328151A825B004123FF /* StringImpl.cpp */, 1090 1094 A8A47329151A825B004123FF /* StringImpl.h */, 1095 0F0F52691F421FF8004A452C /* StringMalloc.cpp */, 1096 0F0F526A1F421FF8004A452C /* StringMalloc.h */, 1091 1097 A8A4732A151A825B004123FF /* StringOperators.h */, 1098 0F348C7D1F47AA9D003CFEF2 /* StringVector.h */, 1092 1099 93F1993D19D7958D00C2390B /* StringView.cpp */, 1093 1100 1A6EB1DF187D0BD30030126F /* StringView.h */, … … 1336 1343 A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */, 1337 1344 E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */, 1345 0F0F526B1F421FF8004A452C /* StringMalloc.cpp in Sources */, 1338 1346 A8A47439151A825B004123FF /* CString.cpp in Sources */, 1339 1347 A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r221330 r221384 183 183 text/StringHash.h 184 184 text/StringImpl.h 185 text/StringMalloc.h 186 text/StringVector.h 185 187 text/StringView.h 186 188 text/SymbolImpl.h … … 287 289 text/StringBuilderJSON.cpp 288 290 text/StringImpl.cpp 291 text/StringMalloc.cpp 289 292 text/StringView.cpp 290 293 text/SymbolImpl.cpp -
trunk/Source/WTF/wtf/Deque.h
r219274 r221384 114 114 friend class DequeIteratorBase<T, inlineCapacity>; 115 115 116 typedef VectorBuffer<T, inlineCapacity > Buffer;116 typedef VectorBuffer<T, inlineCapacity, FastMalloc> Buffer; 117 117 typedef VectorTypeOperations<T> TypeOperations; 118 118 typedef DequeIteratorBase<T, inlineCapacity> IteratorBase; -
trunk/Source/WTF/wtf/FastMalloc.h
r219491 r221384 130 130 template<typename T, typename U> inline bool operator!=(const FastAllocator<T>&, const FastAllocator<U>&) { return false; } 131 131 132 struct FastMalloc { 133 static void* malloc(size_t size) { return fastMalloc(size); } 134 135 static void* tryMalloc(size_t size) 136 { 137 auto result = tryFastMalloc(size); 138 void* realResult; 139 if (result.getValue(realResult)) 140 return realResult; 141 return nullptr; 142 } 143 144 static void* realloc(void* p, size_t size) { return fastRealloc(p, size); } 145 146 static void free(void* p) { fastFree(p); } 147 }; 132 148 133 149 } // namespace WTF … … 137 153 #endif 138 154 155 using WTF::FastAllocator; 156 using WTF::FastMalloc; 139 157 using WTF::isFastMallocEnabled; 140 158 using WTF::fastCalloc; … … 152 170 using WTF::fastAlignedMalloc; 153 171 using WTF::fastAlignedFree; 154 using WTF::FastAllocator;155 172 156 173 #if COMPILER(GCC_OR_CLANG) && OS(DARWIN) -
trunk/Source/WTF/wtf/Forward.h
r216839 r221384 38 38 39 39 template<typename... T> class Variant; 40 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity > class Vector;40 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> class Vector; 41 41 42 42 class AtomicString; -
trunk/Source/WTF/wtf/Gigacage.cpp
r220712 r221384 41 41 void* tryMalloc(Kind, size_t size) 42 42 { 43 auto result = tryFastMalloc(size); 44 void* realResult; 45 if (result.getValue(realResult)) 46 return realResult; 47 return nullptr; 43 return FastMalloc::tryMalloc(size); 48 44 } 49 45 -
trunk/Source/WTF/wtf/Gigacage.h
r221211 r221384 41 41 enum Kind { 42 42 Primitive, 43 JSValue 43 JSValue, 44 String 44 45 }; 45 46 … … 64 65 case JSValue: 65 66 return "JSValue"; 67 case String: 68 return "String"; 66 69 } 67 70 RELEASE_ASSERT_NOT_REACHED(); -
trunk/Source/WTF/wtf/Vector.h
r219702 r221384 1 1 /* 2 * Copyright (C) 2005 , 2006, 2007, 2008, 2014Apple Inc. All rights reserved.2 * Copyright (C) 2005-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 255 255 }; 256 256 257 template<typename T >257 template<typename T, typename Malloc> 258 258 class VectorBufferBase { 259 259 WTF_MAKE_NONCOPYABLE(VectorBufferBase); … … 266 266 size_t sizeToAllocate = newCapacity * sizeof(T); 267 267 m_capacity = sizeToAllocate / sizeof(T); 268 m_buffer = static_cast<T*>( fastMalloc(sizeToAllocate));268 m_buffer = static_cast<T*>(Malloc::malloc(sizeToAllocate)); 269 269 } 270 270 … … 276 276 277 277 size_t sizeToAllocate = newCapacity * sizeof(T); 278 T* newBuffer; 279 if (tryFastMalloc(sizeToAllocate).getValue(newBuffer)) { 280 m_capacity = sizeToAllocate / sizeof(T); 281 m_buffer = newBuffer; 282 return true; 283 } 284 return false; 278 T* newBuffer = static_cast<T*>(Malloc::tryMalloc(sizeToAllocate)); 279 if (!newBuffer) 280 return false; 281 m_capacity = sizeToAllocate / sizeof(T); 282 m_buffer = newBuffer; 283 return true; 285 284 } 286 285 … … 297 296 size_t sizeToAllocate = newCapacity * sizeof(T); 298 297 m_capacity = sizeToAllocate / sizeof(T); 299 m_buffer = static_cast<T*>( fastRealloc(m_buffer, sizeToAllocate));298 m_buffer = static_cast<T*>(Malloc::realloc(m_buffer, sizeToAllocate)); 300 299 } 301 300 … … 310 309 } 311 310 312 fastFree(bufferToDeallocate);311 Malloc::free(bufferToDeallocate); 313 312 } 314 313 … … 351 350 }; 352 351 353 template<typename T, size_t inlineCapacity >352 template<typename T, size_t inlineCapacity, typename Malloc> 354 353 class VectorBuffer; 355 354 356 template<typename T >357 class VectorBuffer<T, 0 > : private VectorBufferBase<T> {355 template<typename T, typename Malloc> 356 class VectorBuffer<T, 0, Malloc> : private VectorBufferBase<T, Malloc> { 358 357 private: 359 typedef VectorBufferBase<T > Base;358 typedef VectorBufferBase<T, Malloc> Base; 360 359 public: 361 360 VectorBuffer() … … 377 376 } 378 377 379 void swap(VectorBuffer<T, 0 >& other, size_t, size_t)378 void swap(VectorBuffer<T, 0, Malloc>& other, size_t, size_t) 380 379 { 381 380 std::swap(m_buffer, other.m_buffer); … … 412 411 }; 413 412 414 template<typename T, size_t inlineCapacity >415 class VectorBuffer : private VectorBufferBase<T > {413 template<typename T, size_t inlineCapacity, typename Malloc> 414 class VectorBuffer : private VectorBufferBase<T, Malloc> { 416 415 WTF_MAKE_NONCOPYABLE(VectorBuffer); 417 416 private: 418 typedef VectorBufferBase<T > Base;417 typedef VectorBufferBase<T, Malloc> Base; 419 418 public: 420 419 VectorBuffer() … … 577 576 }; 578 577 579 template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16 >580 class Vector : private VectorBuffer<T, inlineCapacity > {578 template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16, typename Malloc = FastMalloc> 579 class Vector : private VectorBuffer<T, inlineCapacity, Malloc> { 581 580 WTF_MAKE_FAST_ALLOCATED; 582 581 private: 583 typedef VectorBuffer<T, inlineCapacity > Base;582 typedef VectorBuffer<T, inlineCapacity, Malloc> Base; 584 583 typedef VectorTypeOperations<T> TypeOperations; 585 584 … … 634 633 635 634 Vector(const Vector&); 636 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity >637 explicit Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity >&);635 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc> 636 explicit Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>&); 638 637 639 638 Vector& operator=(const Vector&); 640 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity >641 Vector& operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity >&);639 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc> 640 Vector& operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>&); 642 641 643 642 Vector(Vector&&); … … 815 814 }; 816 815 817 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >818 Vector<T, inlineCapacity, OverflowHandler, minCapacity >::Vector(const Vector& other)816 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 817 Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(const Vector& other) 819 818 : Base(other.capacity(), other.size()) 820 819 { … … 825 824 } 826 825 827 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >828 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity >829 Vector<T, inlineCapacity, OverflowHandler, minCapacity >::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>& other)826 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 827 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc> 828 Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>& other) 830 829 : Base(other.capacity(), other.size()) 831 830 { … … 836 835 } 837 836 838 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >839 Vector<T, inlineCapacity, OverflowHandler, minCapacity >& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& other)837 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 838 Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& other) 840 839 { 841 840 if (&other == this) … … 861 860 inline bool typelessPointersAreEqual(const void* a, const void* b) { return a == b; } 862 861 863 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >864 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity >865 Vector<T, inlineCapacity, OverflowHandler, minCapacity >& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>& other)862 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 863 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc> 864 Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>& other) 866 865 { 867 866 // If the inline capacities match, we should call the more specific … … 887 886 } 888 887 889 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >890 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity >::Vector(Vector<T, inlineCapacity, OverflowHandler, minCapacity>&& other)888 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 889 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>&& other) 891 890 { 892 891 swap(other); 893 892 } 894 893 895 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >896 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity >& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(Vector<T, inlineCapacity, OverflowHandler, minCapacity>&& other)894 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 895 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>&& other) 897 896 { 898 897 swap(other); … … 900 899 } 901 900 902 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >901 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 903 902 template<typename U> 904 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::contains(const U& value) const903 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::contains(const U& value) const 905 904 { 906 905 return find(value) != notFound; 907 906 } 908 907 909 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >908 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 910 909 template<typename MatchFunction> 911 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity >::findMatching(const MatchFunction& matches) const910 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::findMatching(const MatchFunction& matches) const 912 911 { 913 912 for (size_t i = 0; i < size(); ++i) { … … 918 917 } 919 918 920 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >919 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 921 920 template<typename U> 922 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity >::find(const U& value) const921 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::find(const U& value) const 923 922 { 924 923 return findMatching([&](auto& item) { … … 927 926 } 928 927 929 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >928 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 930 929 template<typename U> 931 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity >::reverseFind(const U& value) const930 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reverseFind(const U& value) const 932 931 { 933 932 for (size_t i = 1; i <= size(); ++i) { … … 939 938 } 940 939 941 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >940 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 942 941 template<typename U> 943 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::appendIfNotContains(const U& value)942 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendIfNotContains(const U& value) 944 943 { 945 944 if (contains(value)) … … 949 948 } 950 949 951 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >952 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::fill(const T& val, size_t newSize)950 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 951 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::fill(const T& val, size_t newSize) 953 952 { 954 953 if (size() > newSize) … … 967 966 } 968 967 969 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >968 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 970 969 template<typename Iterator> 971 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::appendRange(Iterator start, Iterator end)970 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendRange(Iterator start, Iterator end) 972 971 { 973 972 for (Iterator it = start; it != end; ++it) … … 975 974 } 976 975 977 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >978 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::expandCapacity(size_t newMinCapacity)976 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 977 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity) 979 978 { 980 979 reserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(minCapacity), capacity() + capacity() / 4 + 1))); 981 980 } 982 981 983 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >984 T* Vector<T, inlineCapacity, OverflowHandler, minCapacity >::expandCapacity(size_t newMinCapacity, T* ptr)982 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 983 T* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity, T* ptr) 985 984 { 986 985 if (ptr < begin() || ptr >= end()) { … … 993 992 } 994 993 995 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >996 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::tryExpandCapacity(size_t newMinCapacity)994 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 995 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryExpandCapacity(size_t newMinCapacity) 997 996 { 998 997 return tryReserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(minCapacity), capacity() + capacity() / 4 + 1))); 999 998 } 1000 999 1001 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1002 const T* Vector<T, inlineCapacity, OverflowHandler, minCapacity >::tryExpandCapacity(size_t newMinCapacity, const T* ptr)1000 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1001 const T* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryExpandCapacity(size_t newMinCapacity, const T* ptr) 1003 1002 { 1004 1003 if (ptr < begin() || ptr >= end()) { … … 1013 1012 } 1014 1013 1015 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1016 inline U* Vector<T, inlineCapacity, OverflowHandler, minCapacity>::expandCapacity(size_t newMinCapacity, U* ptr) 1014 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1015 template<typename U> 1016 inline U* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity, U* ptr) 1017 1017 { 1018 1018 expandCapacity(newMinCapacity); … … 1020 1020 } 1021 1021 1022 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1023 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::resize(size_t size)1022 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1023 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::resize(size_t size) 1024 1024 { 1025 1025 if (size <= m_size) { … … 1037 1037 } 1038 1038 1039 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1040 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::resizeToFit(size_t size)1039 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1040 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::resizeToFit(size_t size) 1041 1041 { 1042 1042 reserveCapacity(size); … … 1044 1044 } 1045 1045 1046 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1047 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::shrink(size_t size)1046 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1047 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::shrink(size_t size) 1048 1048 { 1049 1049 ASSERT(size <= m_size); … … 1053 1053 } 1054 1054 1055 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1056 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::grow(size_t size)1055 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1056 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::grow(size_t size) 1057 1057 { 1058 1058 ASSERT(size >= m_size); … … 1065 1065 } 1066 1066 1067 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1068 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::asanSetInitialBufferSizeTo(size_t size)1067 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1068 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanSetInitialBufferSizeTo(size_t size) 1069 1069 { 1070 1070 #if ASAN_ENABLED … … 1081 1081 } 1082 1082 1083 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1084 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::asanSetBufferSizeToFullCapacity(size_t size)1083 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1084 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanSetBufferSizeToFullCapacity(size_t size) 1085 1085 { 1086 1086 #if ASAN_ENABLED … … 1095 1095 } 1096 1096 1097 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1098 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::asanBufferSizeWillChangeTo(size_t newSize)1097 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1098 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanBufferSizeWillChangeTo(size_t newSize) 1099 1099 { 1100 1100 #if ASAN_ENABLED … … 1109 1109 } 1110 1110 1111 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1112 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::reserveCapacity(size_t newCapacity)1111 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1112 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reserveCapacity(size_t newCapacity) 1113 1113 { 1114 1114 if (newCapacity <= capacity()) … … 1128 1128 } 1129 1129 1130 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1131 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::tryReserveCapacity(size_t newCapacity)1130 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1131 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryReserveCapacity(size_t newCapacity) 1132 1132 { 1133 1133 if (newCapacity <= capacity()) … … 1151 1151 } 1152 1152 1153 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1154 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::reserveInitialCapacity(size_t initialCapacity)1153 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1154 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reserveInitialCapacity(size_t initialCapacity) 1155 1155 { 1156 1156 ASSERT(!m_size); … … 1160 1160 } 1161 1161 1162 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1163 void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::shrinkCapacity(size_t newCapacity)1162 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1163 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::shrinkCapacity(size_t newCapacity) 1164 1164 { 1165 1165 if (newCapacity >= capacity()) … … 1191 1191 } 1192 1192 1193 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1194 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::append(const U* data, size_t dataSize) 1193 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1194 template<typename U> 1195 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::append(const U* data, size_t dataSize) 1195 1196 { 1196 1197 size_t newSize = m_size + dataSize; … … 1207 1208 } 1208 1209 1209 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1210 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryAppend(const U* data, size_t dataSize) 1210 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1211 template<typename U> 1212 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryAppend(const U* data, size_t dataSize) 1211 1213 { 1212 1214 size_t newSize = m_size + dataSize; … … 1226 1228 } 1227 1229 1228 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1229 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::append(U&& value) 1230 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1231 template<typename U> 1232 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::append(U&& value) 1230 1233 { 1231 1234 if (size() != capacity()) { … … 1239 1242 } 1240 1243 1241 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args> 1242 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::constructAndAppend(Args&&... args) 1244 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1245 template<typename... Args> 1246 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::constructAndAppend(Args&&... args) 1243 1247 { 1244 1248 if (size() != capacity()) { … … 1252 1256 } 1253 1257 1254 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args> 1255 ALWAYS_INLINE bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryConstructAndAppend(Args&&... args) 1258 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1259 template<typename... Args> 1260 ALWAYS_INLINE bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryConstructAndAppend(Args&&... args) 1256 1261 { 1257 1262 if (size() != capacity()) { … … 1265 1270 } 1266 1271 1267 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1268 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendSlowCase(U&& value) 1272 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1273 template<typename U> 1274 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendSlowCase(U&& value) 1269 1275 { 1270 1276 ASSERT(size() == capacity()); … … 1279 1285 } 1280 1286 1281 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args> 1282 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::constructAndAppendSlowCase(Args&&... args) 1287 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1288 template<typename... Args> 1289 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::constructAndAppendSlowCase(Args&&... args) 1283 1290 { 1284 1291 ASSERT(size() == capacity()); … … 1292 1299 } 1293 1300 1294 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args> 1295 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryConstructAndAppendSlowCase(Args&&... args) 1301 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1302 template<typename... Args> 1303 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryConstructAndAppendSlowCase(Args&&... args) 1296 1304 { 1297 1305 ASSERT(size() == capacity()); … … 1310 1318 // vector's capacity is large enough for the append to succeed. 1311 1319 1312 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1313 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::uncheckedAppend(U&& value) 1320 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1321 template<typename U> 1322 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::uncheckedAppend(U&& value) 1314 1323 { 1315 1324 ASSERT(size() < capacity()); … … 1322 1331 } 1323 1332 1324 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U, size_t otherCapacity> 1325 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendVector(const Vector<U, otherCapacity>& val) 1333 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1334 template<typename U, size_t otherCapacity> 1335 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(const Vector<U, otherCapacity>& val) 1326 1336 { 1327 1337 append(val.begin(), val.size()); 1328 1338 } 1329 1339 1330 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1331 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insert(size_t position, const U* data, size_t dataSize) 1340 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1341 template<typename U> 1342 void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insert(size_t position, const U* data, size_t dataSize) 1332 1343 { 1333 1344 ASSERT_WITH_SECURITY_IMPLICATION(position <= size()); … … 1346 1357 } 1347 1358 1348 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U> 1349 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insert(size_t position, U&& value) 1359 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1360 template<typename U> 1361 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insert(size_t position, U&& value) 1350 1362 { 1351 1363 ASSERT_WITH_SECURITY_IMPLICATION(position <= size()); … … 1365 1377 } 1366 1378 1367 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U, size_t c> 1368 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insertVector(size_t position, const Vector<U, c>& val) 1379 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1380 template<typename U, size_t c> 1381 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insertVector(size_t position, const Vector<U, c>& val) 1369 1382 { 1370 1383 insert(position, val.begin(), val.size()); 1371 1384 } 1372 1385 1373 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1374 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::remove(size_t position)1386 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1387 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::remove(size_t position) 1375 1388 { 1376 1389 ASSERT_WITH_SECURITY_IMPLICATION(position < size()); … … 1382 1395 } 1383 1396 1384 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1385 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::remove(size_t position, size_t length)1397 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1398 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::remove(size_t position, size_t length) 1386 1399 { 1387 1400 ASSERT_WITH_SECURITY_IMPLICATION(position <= size()); … … 1395 1408 } 1396 1409 1397 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1410 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1398 1411 template<typename U> 1399 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::removeFirst(const U& value)1412 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeFirst(const U& value) 1400 1413 { 1401 1414 return removeFirstMatching([&value] (const T& current) { … … 1404 1417 } 1405 1418 1406 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1419 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1407 1420 template<typename MatchFunction> 1408 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity >::removeFirstMatching(const MatchFunction& matches, size_t startIndex)1421 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeFirstMatching(const MatchFunction& matches, size_t startIndex) 1409 1422 { 1410 1423 for (size_t i = startIndex; i < size(); ++i) { … … 1417 1430 } 1418 1431 1419 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1432 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1420 1433 template<typename U> 1421 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity >::removeAll(const U& value)1434 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeAll(const U& value) 1422 1435 { 1423 1436 return removeAllMatching([&value] (const T& current) { … … 1426 1439 } 1427 1440 1428 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1441 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1429 1442 template<typename MatchFunction> 1430 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity >::removeAllMatching(const MatchFunction& matches, size_t startIndex)1443 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeAllMatching(const MatchFunction& matches, size_t startIndex) 1431 1444 { 1432 1445 iterator holeBegin = end(); … … 1453 1466 } 1454 1467 1455 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1456 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::reverse()1468 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1469 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reverse() 1457 1470 { 1458 1471 for (size_t i = 0; i < m_size / 2; ++i) … … 1460 1473 } 1461 1474 1462 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename MapFunction, typename R> 1463 inline Vector<R> Vector<T, inlineCapacity, OverflowHandler, minCapacity>::map(MapFunction mapFunction) const 1475 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1476 template<typename MapFunction, typename R> 1477 inline Vector<R> Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::map(MapFunction mapFunction) const 1464 1478 { 1465 1479 Vector<R> result; … … 1470 1484 } 1471 1485 1472 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1473 inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler, minCapacity >::releaseBuffer()1486 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1487 inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::releaseBuffer() 1474 1488 { 1475 1489 // FIXME: Find a way to preserve annotations on the returned buffer. … … 1484 1498 // we create a brand new buffer so the caller always gets one. 1485 1499 size_t bytes = m_size * sizeof(T); 1486 buffer = adoptMallocPtr(static_cast<T*>( fastMalloc(bytes)));1500 buffer = adoptMallocPtr(static_cast<T*>(Malloc::malloc(bytes))); 1487 1501 memcpy(buffer.get(), data(), bytes); 1488 1502 } … … 1492 1506 } 1493 1507 1494 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1495 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity >::checkConsistency()1508 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1509 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::checkConsistency() 1496 1510 { 1497 1511 #if !ASSERT_DISABLED … … 1501 1515 } 1502 1516 1503 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1504 inline void swap(Vector<T, inlineCapacity, OverflowHandler, minCapacity >& a, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)1517 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1518 inline void swap(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b) 1505 1519 { 1506 1520 a.swap(b); 1507 1521 } 1508 1522 1509 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1510 bool operator==(const Vector<T, inlineCapacity, OverflowHandler, minCapacity >& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)1523 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1524 bool operator==(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b) 1511 1525 { 1512 1526 if (a.size() != b.size()) … … 1516 1530 } 1517 1531 1518 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1519 inline bool operator!=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity >& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)1532 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1533 inline bool operator!=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b) 1520 1534 { 1521 1535 return !(a == b); … … 1541 1555 } 1542 1556 1543 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity >1544 size_t removeRepeatedElements(Vector<T, inlineCapacity, OverflowHandler, minCapacity >& vector)1557 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> 1558 size_t removeRepeatedElements(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& vector) 1545 1559 { 1546 1560 return removeRepeatedElements(vector, [] (T& a, T& b) { return a == b; }); -
trunk/Source/WTF/wtf/text/AtomicStringImpl.h
r219347 r221384 104 104 // AtomicStringImpls created from StaticStringImpl will ASSERT 105 105 // in the generic ValueCheck<T>::checkConsistency 106 // as they are not allocated by fastMalloc.106 // as they are not allocated by StringMalloc. 107 107 // We don't currently have any way to detect that case 108 108 // so we ignore the consistency check for all AtomicStringImpls*. -
trunk/Source/WTF/wtf/text/CString.cpp
r201782 r221384 1 1 /* 2 * Copyright (C) 2003 , 2006, 2008, 2009, 2010, 2012Apple Inc. All rights reserved.2 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #include <string.h> 31 31 #include <wtf/Hasher.h> 32 #include <wtf/text/StringMalloc.h> 32 33 33 34 namespace WTF { … … 39 40 // The +1 is for the terminating null character. 40 41 size_t size = sizeof(CStringBuffer) + length + 1; 41 CStringBuffer* stringBuffer = static_cast<CStringBuffer*>( fastMalloc(size));42 CStringBuffer* stringBuffer = static_cast<CStringBuffer*>(stringMalloc(size)); 42 43 return adoptRef(*new (NotNull, stringBuffer) CStringBuffer(length)); 43 44 } -
trunk/Source/WTF/wtf/text/CString.h
r201782 r221384 1 1 /* 2 * Copyright (C) 2003 , 2006, 2008, 2009, 2010, 2012Apple Inc. All rights reserved.2 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 #include <wtf/Ref.h> 32 32 #include <wtf/RefCounted.h> 33 #include <wtf/text/StringMalloc.h> 33 34 34 35 namespace WTF { … … 37 38 // The data is implicitly allocated 1 character longer than length(), as it is zero-terminated. 38 39 class CStringBuffer : public RefCounted<CStringBuffer> { 40 WTF_MAKE_STRING_ALLOCATED; 39 41 public: 40 42 const char* data() { return mutableData(); } -
trunk/Source/WTF/wtf/text/StringBuffer.h
r163310 r221384 31 31 32 32 #include <wtf/Assertions.h> 33 #include <wtf/text/StringMalloc.h> 33 34 #include <limits> 34 35 #include <unicode/utypes.h> … … 42 43 explicit StringBuffer(unsigned length) 43 44 : m_length(length) 44 , m_data(m_length ? static_cast<CharType*>( fastMalloc((Checked<size_t>(m_length) * sizeof(CharType)).unsafeGet())) : nullptr)45 , m_data(m_length ? static_cast<CharType*>(stringMalloc((Checked<size_t>(m_length) * sizeof(CharType)).unsafeGet())) : nullptr) 45 46 { 46 47 } … … 48 49 ~StringBuffer() 49 50 { 50 fastFree(m_data);51 stringFree(m_data); 51 52 } 52 53 … … 62 63 if (newLength > std::numeric_limits<unsigned>::max() / sizeof(UChar)) 63 64 CRASH(); 64 m_data = static_cast<UChar*>( fastRealloc(m_data, newLength * sizeof(UChar)));65 m_data = static_cast<UChar*>(stringRealloc(m_data, newLength * sizeof(UChar))); 65 66 } 66 67 m_length = newLength; -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r219237 r221384 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 5 * Copyright (C) 2003-20 09, 2013-2016Apple Inc. All rights reserved.5 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 6 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 7 7 * … … 29 29 #include "StringBuffer.h" 30 30 #include "StringHash.h" 31 #include <wtf/Gigacage.h> 31 32 #include <wtf/ProcessID.h> 32 33 #include <wtf/StdLibExtras.h> 33 34 #include <wtf/text/CString.h> 35 #include <wtf/text/StringMalloc.h> 34 36 #include <wtf/text/StringView.h> 35 37 #include <wtf/text/SymbolImpl.h> … … 130 132 // We use m_data8, but since it is a union with m_data16 this works either way. 131 133 ASSERT(m_data8); 132 fastFree(const_cast<LChar*>(m_data8));134 stringFree(const_cast<LChar*>(m_data8)); 133 135 return; 134 136 } … … 142 144 { 143 145 stringImpl->~StringImpl(); 144 fastFree(stringImpl);146 stringFree(stringImpl); 145 147 } 146 148 … … 193 195 if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType))) 194 196 CRASH(); 195 StringImpl* string = static_cast<StringImpl*>( fastMalloc(allocationSize<CharType>(length)));197 StringImpl* string = static_cast<StringImpl*>(stringMalloc(allocationSize<CharType>(length))); 196 198 197 199 data = string->tailPointer<CharType>(); … … 220 222 } 221 223 222 // Same as createUninitialized() except here we use fastRealloc.224 // Same as createUninitialized() except here we use stringRealloc. 223 225 if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType))) 224 226 CRASH(); 225 227 226 228 originalString->~StringImpl(); 227 auto* string = static_cast<StringImpl*>( fastRealloc(&originalString.leakRef(), allocationSize<CharType>(length)));229 auto* string = static_cast<StringImpl*>(stringRealloc(&originalString.leakRef(), allocationSize<CharType>(length))); 228 230 229 231 data = string->tailPointer<CharType>(); … … 2178 2180 } 2179 2181 2182 void StringImpl::releaseAssertCaged() const 2183 { 2184 if (isStatic()) 2185 return; 2186 RELEASE_ASSERT(!GIGACAGE_ENABLED || Gigacage::isCaged(Gigacage::String, this)); 2187 if (bufferOwnership() != BufferOwned) 2188 return; 2189 RELEASE_ASSERT(!GIGACAGE_ENABLED || Gigacage::isCaged(Gigacage::String, m_data8)); 2190 } 2191 2180 2192 } // namespace WTF -
trunk/Source/WTF/wtf/text/StringImpl.h
r220053 r221384 36 36 #include <wtf/text/ConversionMode.h> 37 37 #include <wtf/text/StringCommon.h> 38 #include <wtf/text/StringMalloc.h> 39 #include <wtf/text/StringVector.h> 38 40 39 41 #if USE(CF) … … 179 181 180 182 class StringImpl : private StringImplShape { 181 WTF_MAKE_NONCOPYABLE(StringImpl); WTF_MAKE_ FAST_ALLOCATED;183 WTF_MAKE_NONCOPYABLE(StringImpl); WTF_MAKE_STRING_ALLOCATED; 182 184 friend struct WTF::CStringTranslator; 183 185 template<typename CharacterType> friend struct WTF::HashAndCharactersTranslator; … … 194 196 friend class RegisteredSymbolImpl; 195 197 196 p rivate:198 public: 197 199 enum BufferOwnership { 198 200 BufferInternal, … … 202 204 203 205 // The bottom 6 bits in the hash are flags. 204 public:205 206 static constexpr const unsigned s_flagCount = 6; 206 207 private: … … 338 339 339 340 // We allocate a buffer that contains both the StringImpl struct as well as the pointer to the owner string. 340 auto* stringImpl = static_cast<StringImpl*>( fastMalloc(allocationSize<StringImpl*>(1)));341 auto* stringImpl = static_cast<StringImpl*>(stringMalloc(allocationSize<StringImpl*>(1))); 341 342 if (rep.is8Bit()) 342 343 return adoptRef(*new (NotNull, stringImpl) StringImpl(rep.m_data8 + offset, length, *ownerRep)); … … 373 374 return nullptr; 374 375 } 375 StringImpl* resultImpl ;376 if (! tryFastMalloc(allocationSize<T>(length)).getValue(resultImpl)) {376 StringImpl* resultImpl = static_cast<StringImpl*>(tryStringMalloc(allocationSize<T>(length))); 377 if (!resultImpl) { 377 378 output = nullptr; 378 379 return nullptr; … … 396 397 static unsigned dataOffset() { return OBJECT_OFFSETOF(StringImpl, m_data8); } 397 398 398 template<typename CharType, size_t inlineCapacity, typename OverflowHandler >399 static Ref<StringImpl> adopt( Vector<CharType, inlineCapacity, OverflowHandler>&& vector)399 template<typename CharType, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> 400 static Ref<StringImpl> adopt(StringVector<CharType, inlineCapacity, OverflowHandler, minCapacity>&& vector) 400 401 { 401 402 if (size_t size = vector.size()) { … … 758 759 #endif 759 760 761 BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership>(m_hashAndFlags & s_hashMaskBufferOwnership); } 762 763 void assertCaged() const 764 { 765 if (!ASSERT_DISABLED) 766 releaseAssertCaged(); 767 } 768 769 WTF_EXPORT_PRIVATE void releaseAssertCaged() const; 770 760 771 protected: 761 772 ~StringImpl(); … … 847 858 template<CaseConvertType type, typename CharacterType> static Ref<StringImpl> convertASCIICase(StringImpl&, const CharacterType*, unsigned); 848 859 849 BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership>(m_hashAndFlags & s_hashMaskBufferOwnership); }850 860 template <class UCharPredicate> Ref<StringImpl> stripMatchedCharacters(UCharPredicate); 851 861 template <typename CharType, class UCharPredicate> Ref<StringImpl> simplifyMatchedCharactersToSpace(UCharPredicate); … … 882 892 // StringImpls created from StaticStringImpl will ASSERT 883 893 // in the generic ValueCheck<T>::checkConsistency 884 // as they are not allocated by fastMalloc.894 // as they are not allocated by stringMalloc. 885 895 // We don't currently have any way to detect that case 886 896 // so we ignore the consistency check for all StringImpl*. -
trunk/Source/WTF/wtf/text/SymbolImpl.h
r220053 r221384 203 203 // SymbolImpls created from StaticStringImpl will ASSERT 204 204 // in the generic ValueCheck<T>::checkConsistency 205 // as they are not allocated by fastMalloc.205 // as they are not allocated by stringMalloc. 206 206 // We don't currently have any way to detect that case 207 207 // so we ignore the consistency check for all SymbolImpls*. -
trunk/Source/WTF/wtf/text/UniquedStringImpl.h
r210227 r221384 45 45 // UniquedStringImpls created from StaticStringImpl will ASSERT 46 46 // in the generic ValueCheck<T>::checkConsistency 47 // as they are not allocated by fastMalloc.47 // as they are not allocated by stringMalloc. 48 48 // We don't currently have any way to detect that case 49 49 // so we ignore the consistency check for all UniquedStringImpls*. -
trunk/Source/WTF/wtf/text/WTFString.h
r221203 r221384 147 147 static String adopt(StringBuffer<LChar>&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } 148 148 static String adopt(StringBuffer<UChar>&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } 149 template<typename CharacterType, size_t inlineCapacity, typename OverflowHandler >150 static String adopt( Vector<CharacterType, inlineCapacity, OverflowHandler>&& vector) { return StringImpl::adopt(WTFMove(vector)); }149 template<typename CharacterType, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> 150 static String adopt(StringVector<CharacterType, inlineCapacity, OverflowHandler, minCapacity>&& vector) { return StringImpl::adopt(WTFMove(vector)); } 151 151 152 152 bool isNull() const { return !m_impl; } … … 499 499 if (m_impl && m_impl->hasOneRef()) 500 500 m_impl = nullptr; 501 } 502 503 void assertCaged() const 504 { 505 if (m_impl) 506 m_impl->assertCaged(); 507 } 508 509 void releaseAssertCaged() const 510 { 511 if (m_impl) 512 m_impl->releaseAssertCaged(); 501 513 } 502 514 -
trunk/Source/WebCore/ChangeLog
r221381 r221384 1 2017-08-22 Filip Pizlo <fpizlo@apple.com> 2 3 Strings need to be in some kind of gigacage 4 https://bugs.webkit.org/show_bug.cgi?id=174924 5 6 Reviewed by Oliver Hunt. 7 8 No new tests because no new behavior. 9 10 * html/canvas/CanvasRenderingContext2D.cpp: 11 (WebCore::normalizeSpaces): 12 1 13 2017-08-30 Andy Estes <aestes@apple.com> 2 14 -
trunk/Source/WebCore/Modules/indexeddb/server/IDBSerialization.cpp
r215262 r221384 327 327 return false; 328 328 329 Vector<UChar> buffer;329 StringVector<UChar> buffer; 330 330 buffer.reserveInitialCapacity(length); 331 331 for (size_t i = 0; i < length; i++) { -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r221110 r221384 1951 1951 ptr += length * sizeof(UChar); 1952 1952 #else 1953 Vector<UChar> buffer;1953 StringVector<UChar> buffer; 1954 1954 buffer.reserveCapacity(length); 1955 1955 for (unsigned i = 0; i < length; i++) { -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r220503 r221384 2326 2326 2327 2327 unsigned textLength = text.length(); 2328 Vector<UChar> charVector(textLength);2328 StringVector<UChar> charVector(textLength); 2329 2329 StringView(text).getCharactersWithUpconvert(charVector.data()); 2330 2330 -
trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
r219237 r221384 206 206 { 207 207 ASSERT(!isEmpty()); 208 Vector<LChar, 8> whitespace;208 StringVector<LChar, 8> whitespace; 209 209 do { 210 210 UChar character = m_text[0]; -
trunk/Source/WebCore/platform/URLParser.cpp
r221195 r221384 534 534 } 535 535 536 static void percentEncodeByte(uint8_t byte, Vector<LChar>& buffer)536 static void percentEncodeByte(uint8_t byte, StringVector<LChar>& buffer) 537 537 { 538 538 buffer.append('%'); … … 2815 2815 } 2816 2816 2817 static void serializeURLEncodedForm(const String& input, Vector<LChar>& output)2817 static void serializeURLEncodedForm(const String& input, StringVector<LChar>& output) 2818 2818 { 2819 2819 auto utf8 = input.utf8(StrictConversion); … … 2841 2841 return { }; 2842 2842 2843 Vector<LChar> output;2843 StringVector<LChar> output; 2844 2844 for (auto& tuple : tuples) { 2845 2845 if (!output.isEmpty()) -
trunk/Source/WebCore/platform/URLParser.h
r213686 r221384 59 59 60 60 URL m_url; 61 Vector<LChar> m_asciiBuffer;61 StringVector<LChar> m_asciiBuffer; 62 62 bool m_urlIsSpecial { false }; 63 63 bool m_urlIsFile { false }; -
trunk/Source/WebCore/platform/graphics/FourCC.cpp
r217933 r221384 43 43 String FourCC::toString() const 44 44 { 45 Vector<LChar, 4> data = {45 StringVector<LChar, 4> data = { 46 46 LChar(value >> 24), 47 47 LChar((value >> 16) & 0xFF), -
trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
r220503 r221384 2699 2699 size_t vectorSize = (depth + bitsPerUChar - 1) / bitsPerUChar; 2700 2700 2701 Vector<UChar> result(vectorSize);2701 StringVector<UChar> result(vectorSize); 2702 2702 result.fill(0); 2703 2703 -
trunk/Source/WebCore/platform/text/LocaleICU.cpp
r206196 r221384 74 74 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) 75 75 return String(); 76 Vector<UChar> buffer(bufferLength);76 StringVector<UChar> buffer(bufferLength); 77 77 status = U_ZERO_ERROR; 78 78 unum_getSymbol(m_numberFormat, symbol, buffer.data(), bufferLength, &status); … … 89 89 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) 90 90 return String(); 91 Vector<UChar> buffer(bufferLength);91 StringVector<UChar> buffer(bufferLength); 92 92 status = U_ZERO_ERROR; 93 93 unum_getTextAttribute(m_numberFormat, tag, buffer.data(), bufferLength, &status); … … 154 154 if (status != U_BUFFER_OVERFLOW_ERROR || !length) 155 155 return emptyString(); 156 Vector<UChar> buffer(length);156 StringVector<UChar> buffer(length); 157 157 status = U_ZERO_ERROR; 158 158 udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status); … … 176 176 if (status != U_BUFFER_OVERFLOW_ERROR) 177 177 return std::make_unique<Vector<String>>(); 178 Vector<UChar> buffer(length);178 StringVector<UChar> buffer(length); 179 179 status = U_ZERO_ERROR; 180 180 udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status); … … 267 267 int32_t length = udatpg_getBestPattern(patternGenerator, skeleton, skeletonLength, 0, 0, &status); 268 268 if (status == U_BUFFER_OVERFLOW_ERROR && length) { 269 Vector<UChar> buffer(length);269 StringVector<UChar> buffer(length); 270 270 status = U_ZERO_ERROR; 271 271 udatpg_getBestPattern(patternGenerator, skeleton, skeletonLength, buffer.data(), length, &status); -
trunk/Source/WebCore/platform/text/mac/TextCodecMac.cpp
r206196 r221384 202 202 return String(); 203 203 204 Vector<UChar> result;204 StringVector<UChar> result; 205 205 206 206 const unsigned char* sourcePointer = reinterpret_cast<const unsigned char*>(bytes); -
trunk/Source/WebCore/platform/win/FileSystemWin.cpp
r221177 r221384 186 186 String pathByAppendingComponent(const String& path, const String& component) 187 187 { 188 Vector<UChar> buffer(MAX_PATH);188 StringVector<UChar> buffer(MAX_PATH); 189 189 190 190 if (path.length() + 1 > buffer.size()) … … 277 277 static String storageDirectory(DWORD pathIdentifier) 278 278 { 279 Vector<UChar> buffer(MAX_PATH);279 StringVector<UChar> buffer(MAX_PATH); 280 280 if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data()))) 281 281 return String(); -
trunk/Source/bmalloc/ChangeLog
r221213 r221384 1 2017-08-22 Filip Pizlo <fpizlo@apple.com> 2 3 Strings need to be in some kind of gigacage 4 https://bugs.webkit.org/show_bug.cgi?id=174924 5 6 Reviewed by Oliver Hunt. 7 8 This adds a StringGigacage. 9 10 * bmalloc/Gigacage.cpp: 11 * bmalloc/Gigacage.h: 12 (Gigacage::name): 13 (Gigacage::basePtr): 14 (Gigacage::forEachKind): 15 * bmalloc/HeapKind.h: 16 (bmalloc::isGigacage): 17 (bmalloc::gigacageKind): 18 (bmalloc::heapKind): 19 1 20 2017-08-25 Daniel Bates <dabates@apple.com> 2 21 -
trunk/Source/bmalloc/bmalloc/Gigacage.cpp
r221148 r221384 37 37 void* g_primitiveGigacageBasePtr; 38 38 void* g_jsValueGigacageBasePtr; 39 void* g_stringGigacageBasePtr; 39 40 40 41 using namespace bmalloc; -
trunk/Source/bmalloc/bmalloc/Gigacage.h
r221148 r221384 35 35 #define PRIMITIVE_GIGACAGE_SIZE 0x800000000llu 36 36 #define JSVALUE_GIGACAGE_SIZE 0x400000000llu 37 #define STRING_GIGACAGE_SIZE 0x400000000llu 37 38 38 39 #define GIGACAGE_SIZE_TO_MASK(size) ((size) - 1) … … 40 41 #define PRIMITIVE_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(PRIMITIVE_GIGACAGE_SIZE) 41 42 #define JSVALUE_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(JSVALUE_GIGACAGE_SIZE) 43 #define STRING_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(STRING_GIGACAGE_SIZE) 42 44 43 45 // FIXME: Consider making this 32GB, in case unsigned 32-bit indices find their way into indexed accesses. … … 48 50 // https://bugs.webkit.org/show_bug.cgi?id=175921 49 51 #define JSVALUE_GIGACAGE_RUNWAY 0 52 #define STRING_GIGACAGE_RUNWAY 0 50 53 51 54 #if BOS(DARWIN) && BCPU(X86_64) … … 57 60 extern "C" BEXPORT void* g_primitiveGigacageBasePtr; 58 61 extern "C" BEXPORT void* g_jsValueGigacageBasePtr; 62 extern "C" BEXPORT void* g_stringGigacageBasePtr; 59 63 60 64 namespace Gigacage { … … 62 66 enum Kind { 63 67 Primitive, 64 JSValue 68 JSValue, 69 String 65 70 }; 66 71 … … 86 91 case JSValue: 87 92 return "JSValue"; 93 case String: 94 return "String"; 88 95 } 89 96 BCRASH(); … … 98 105 case JSValue: 99 106 return g_jsValueGigacageBasePtr; 107 case String: 108 return g_stringGigacageBasePtr; 100 109 } 101 110 BCRASH(); … … 110 119 case JSValue: 111 120 return static_cast<size_t>(JSVALUE_GIGACAGE_SIZE); 121 case String: 122 return static_cast<size_t>(STRING_GIGACAGE_SIZE); 112 123 } 113 124 BCRASH(); … … 132 143 case JSValue: 133 144 return static_cast<size_t>(JSVALUE_GIGACAGE_RUNWAY); 145 case String: 146 return static_cast<size_t>(STRING_GIGACAGE_RUNWAY); 134 147 } 135 148 BCRASH(); … … 147 160 func(Primitive); 148 161 func(JSValue); 162 func(String); 149 163 } 150 164 -
trunk/Source/bmalloc/bmalloc/HeapKind.h
r220352 r221384 35 35 Primary, 36 36 PrimitiveGigacage, 37 JSValueGigacage 37 JSValueGigacage, 38 StringGigacage 38 39 }; 39 40 40 static constexpr unsigned numHeaps = 3;41 static constexpr unsigned numHeaps = 4; 41 42 42 43 BINLINE bool isGigacage(HeapKind heapKind) … … 47 48 case HeapKind::PrimitiveGigacage: 48 49 case HeapKind::JSValueGigacage: 50 case HeapKind::StringGigacage: 49 51 return true; 50 52 } … … 63 65 case HeapKind::JSValueGigacage: 64 66 return Gigacage::JSValue; 67 case HeapKind::StringGigacage: 68 return Gigacage::String; 65 69 } 66 70 BCRASH(); … … 75 79 case Gigacage::JSValue: 76 80 return HeapKind::JSValueGigacage; 81 case Gigacage::String: 82 return HeapKind::StringGigacage; 77 83 } 78 84 BCRASH();
Note: See TracChangeset
for help on using the changeset viewer.