Source/WTF/ChangeLog

 12013-05-20 Anders Carlsson <andersca@apple.com>
 2
 3 Add WTF::NeverDestroyed and start using it in WTF
 4 https://bugs.webkit.org/show_bug.cgi?id=116472
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 NeverDestroyed is a class template that can be used for singletons and other objects that we never
 9 want to destroy. It's intended as a replacement for WTF_STATIC_LOCAL with the advantage that it doesn't
 10 fragment the heap.
 11
 12 * GNUmakefile.list.am:
 13 * WTF.vcproj/WTF.vcproj:
 14 * WTF.vcxproj/WTF.vcxproj:
 15 * WTF.vcxproj/WTF.vcxproj.filters:
 16 * WTF.xcodeproj/project.pbxproj:
 17 Add NeverDestroyed.h
 18
 19 * wtf/Compiler.h:
 20 Add a helper macro, WTF_DELETED_FUNCTION.
 21
 22 * wtf/CryptographicallyRandomNumber.cpp:
 23 Use NeverDestroyed.
 24
 25 * wtf/NeverDestroyed.h: Added.
 26
 27 * wtf/Noncopyable.h:
 28 Use WTF_DELETED_FUNCTION.
 29
 30 * wtf/text/WTFString.cpp:
 31 (WTF::emptyString):
 32 Use
 33
1342013-05-19 Anders Carlsson <andersca@apple.com>
235
336 Remove link prerendering code

Source/WTF/GNUmakefile.list.am

@@wtf_sources += \
8989 Source/WTF/wtf/MetaAllocator.cpp \
9090 Source/WTF/wtf/MetaAllocator.h \
9191 Source/WTF/wtf/MetaAllocatorHandle.h \
 92 Source/WTF/wtf/NeverDestroyed.h \
9293 Source/WTF/wtf/NonCopyingSort.h \
9394 Source/WTF/wtf/Noncopyable.h \
9495 Source/WTF/wtf/NotFound.h \

Source/WTF/WTF.vcproj/WTF.vcproj

935935 >
936936 </File>
937937 <File
 938 RelativePath="..\wtf\NeverDestroyed.h"
 939 >
 940 </File>
 941 <File
938942 RelativePath="..\wtf\Noncopyable.h"
939943 >
940944 </File>

Source/WTF/WTF.vcxproj/WTF.vcxproj

166166 <ClInclude Include="..\wtf\MessageQueue.h" />
167167 <ClInclude Include="..\wtf\MetaAllocator.h" />
168168 <ClInclude Include="..\wtf\MetaAllocatorHandle.h" />
 169 <ClInclude Include="..\wtf\NeverDestroyed.h" />
169170 <ClInclude Include="..\wtf\Noncopyable.h" />
170171 <ClInclude Include="..\wtf\NonCopyingSort.h" />
171172 <ClInclude Include="..\wtf\NotFound.h" />

Source/WTF/WTF.vcxproj/WTF.vcxproj.filters

501501 <ClInclude Include="..\wtf\MetaAllocatorHandle.h">
502502 <Filter>wtf</Filter>
503503 </ClInclude>
 504 <ClInclude Include="..\wtf\NeverDestroyed.h">
 505 <Filter>wtf</Filter>
 506 </ClInclude>
504507 <ClInclude Include="..\wtf\Noncopyable.h">
505508 <Filter>wtf</Filter>
506509 </ClInclude>

Source/WTF/WTF.xcodeproj/project.pbxproj

306306 14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaturatedArithmetic.h; sourceTree = "<group>"; };
307307 1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionDispatcher.h; sourceTree = "<group>"; };
308308 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionDispatcher.cpp; sourceTree = "<group>"; };
 309 1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
309310 1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
310311 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
311312 2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };

690691 A8A472CD151A825B004123FF /* MetaAllocator.cpp */,
691692 A8A472CE151A825B004123FF /* MetaAllocator.h */,
692693 A8A472CF151A825B004123FF /* MetaAllocatorHandle.h */,
 694 1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */,
693695 A8A472D0151A825B004123FF /* Noncopyable.h */,
694696 A8A472D1151A825B004123FF /* NonCopyingSort.h */,
695697 A8A472D2151A825B004123FF /* NotFound.h */,

Source/WTF/wtf/Compiler.h

6565#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
6666#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
6767#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_extension(cxx_reference_qualified_functions)
68 
6968#endif
7069
7170#ifndef CLANG_PRAGMA

276275#define FINAL
277276#endif
278277
 278#if COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
 279#define WTF_DELETED_FUNCTION = delete
 280#else
 281#define WTF_DELETED_FUNCTION
 282#endif
 283
279284/* REFERENCED_FROM_ASM */
280285
281286#ifndef REFERENCED_FROM_ASM

@@inline void unusedParam(T& x) { (void)x; }
320325#define UNUSED_LABEL(label) UNUSED_PARAM(&& label)
321326#endif
322327
 328
 329
323330#endif /* WTF_Compiler_h */

Source/WTF/wtf/CryptographicallyRandomNumber.cpp

3030#include "config.h"
3131#include "CryptographicallyRandomNumber.h"
3232
 33#include "NeverDestroyed.h"
3334#include "OSRandomSource.h"
34 #include "StdLibExtras.h"
3535#include "ThreadingPrimitives.h"
3636
3737namespace WTF {

@@void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
158158
159159ARC4RandomNumberGenerator& sharedRandomNumberGenerator()
160160{
161  DEFINE_STATIC_LOCAL(ARC4RandomNumberGenerator, randomNumberGenerator, ());
 161 static NeverDestroyed<ARC4RandomNumberGenerator> randomNumberGenerator;
 162
162163 return randomNumberGenerator;
163164}
164165

Source/WTF/wtf/NeverDestroyed.h

 1/*
 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef NeverDestroyed_h
 27#define NeverDestroyed_h
 28
 29#include <wtf/Alignment.h>
 30#include <wtf/Noncopyable.h>
 31#include <wtf/StdLibExtras.h>
 32#include <wtf/TypeTraits.h>
 33
 34// NeverDestroyed is a smart pointer like class who ensures that the destructor
 35// for the given object is never called, but doesn't use the heap to allocate it.
 36// It's useful for static local variables, and can be used like so:
 37//
 38// MySharedGlobal& mySharedGlobal()
 39// {
 40// static NeverDestroyed<MySharedGlobal> myGlobal("Hello", 42);
 41// return myGlobal;
 42// }
 43//
 44
 45namespace WTF {
 46
 47template<typename T> class NeverDestroyed {
 48 WTF_MAKE_NONCOPYABLE(NeverDestroyed);
 49
 50public:
 51#if COMPILER_SUPPORTS(CXX_VARIADIC_TEMPLATES)
 52 template<typename... Args>
 53 NeverDestroyed(Args&&... args)
 54 {
 55 new (asPtr()) T(std::forward<Args>(args)...);
 56 }
 57#else
 58 NeverDestroyed()
 59 {
 60 new (NotNull, asPtr()) T;
 61 }
 62
 63 template<typename P1>
 64 NeverDestroyed(const P1& p1)
 65 {
 66 new (NotNull, asPtr()) T(p1);
 67 }
 68#endif
 69
 70 operator T&() { return *asPtr(); }
 71
 72private:
 73#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
 74 NeverDestroyed(NeverDestroyed&&) WTF_DELETED_FUNCTION;
 75#endif
 76
 77 typedef typename WTF::RemoveConst<T>::Type *PointerType;
 78
 79 PointerType asPtr() { return reinterpret_cast<PointerType>(&m_storage); }
 80
 81 // FIXME: Investigate whether we should allocate a hunk of virtual memory
 82 // and hand out chunks of it to NeverDestroyed instead, to reduce fragmentation.
 83 AlignedBuffer<sizeof(T), WTF_ALIGN_OF(T)> m_storage;
 84};
 85
 86} // namespace WTF;
 87
 88using WTF::NeverDestroyed;
 89
 90#endif // NeverDestroyed_h

Source/WTF/wtf/Noncopyable.h

2323
2424#include <wtf/Compiler.h>
2525
26 #if COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
27  #define WTF_MAKE_NONCOPYABLE(ClassName) \
28  private: \
29  ClassName(const ClassName&) = delete; \
30  ClassName& operator=(const ClassName&) = delete;
31 #else
32  #define WTF_MAKE_NONCOPYABLE(ClassName) \
33  private: \
34  ClassName(const ClassName&); \
35  ClassName& operator=(const ClassName&)
36 #endif
 26#define WTF_MAKE_NONCOPYABLE(ClassName) \
 27 private: \
 28 ClassName(const ClassName&) WTF_DELETED_FUNCTION; \
 29 ClassName& operator=(const ClassName&) WTF_DELETED_FUNCTION; \
3730
3831#endif // WTF_Noncopyable_h

Source/WTF/wtf/text/WTFString.cpp

2828#include <wtf/DataLog.h>
2929#include <wtf/HexNumber.h>
3030#include <wtf/MathExtras.h>
 31#include <wtf/NeverDestroyed.h>
3132#include <wtf/text/CString.h>
3233#include <wtf/StringExtras.h>
3334#include <wtf/Vector.h>

@@float charactersToFloat(const UChar* data, size_t length, size_t& parsedLength)
12421243
12431244const String& emptyString()
12441245{
1245  DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty()));
 1246 static NeverDestroyed<String> emptyString(StringImpl::empty());
 1247
12461248 return emptyString;
12471249}
12481250