- a/Source/WTF/ChangeLog +33 lines
Lines 1-3 a/Source/WTF/ChangeLog_sec1
1
2013-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
1
2013-05-19  Anders Carlsson  <andersca@apple.com>
34
2013-05-19  Anders Carlsson  <andersca@apple.com>
2
35
3
        Remove link prerendering code
36
        Remove link prerendering code
- a/Source/WTF/GNUmakefile.list.am +1 lines
Lines 89-94 wtf_sources += \ a/Source/WTF/GNUmakefile.list.am_sec1
89
    Source/WTF/wtf/MetaAllocator.cpp \
89
    Source/WTF/wtf/MetaAllocator.cpp \
90
    Source/WTF/wtf/MetaAllocator.h \
90
    Source/WTF/wtf/MetaAllocator.h \
91
    Source/WTF/wtf/MetaAllocatorHandle.h \
91
    Source/WTF/wtf/MetaAllocatorHandle.h \
92
    Source/WTF/wtf/NeverDestroyed.h \
92
    Source/WTF/wtf/NonCopyingSort.h \
93
    Source/WTF/wtf/NonCopyingSort.h \
93
    Source/WTF/wtf/Noncopyable.h \
94
    Source/WTF/wtf/Noncopyable.h \
94
    Source/WTF/wtf/NotFound.h \
95
    Source/WTF/wtf/NotFound.h \
- a/Source/WTF/WTF.vcproj/WTF.vcproj +4 lines
Lines 935-940 a/Source/WTF/WTF.vcproj/WTF.vcproj_sec1
935
			>
935
			>
936
		</File>
936
		</File>
937
		<File
937
		<File
938
			RelativePath="..\wtf\NeverDestroyed.h"
939
			>
940
		</File>
941
		<File
938
			RelativePath="..\wtf\Noncopyable.h"
942
			RelativePath="..\wtf\Noncopyable.h"
939
			>
943
			>
940
		</File>
944
		</File>
- a/Source/WTF/WTF.vcxproj/WTF.vcxproj +1 lines
Lines 166-171 a/Source/WTF/WTF.vcxproj/WTF.vcxproj_sec1
166
    <ClInclude Include="..\wtf\MessageQueue.h" />
166
    <ClInclude Include="..\wtf\MessageQueue.h" />
167
    <ClInclude Include="..\wtf\MetaAllocator.h" />
167
    <ClInclude Include="..\wtf\MetaAllocator.h" />
168
    <ClInclude Include="..\wtf\MetaAllocatorHandle.h" />
168
    <ClInclude Include="..\wtf\MetaAllocatorHandle.h" />
169
    <ClInclude Include="..\wtf\NeverDestroyed.h" />
169
    <ClInclude Include="..\wtf\Noncopyable.h" />
170
    <ClInclude Include="..\wtf\Noncopyable.h" />
170
    <ClInclude Include="..\wtf\NonCopyingSort.h" />
171
    <ClInclude Include="..\wtf\NonCopyingSort.h" />
171
    <ClInclude Include="..\wtf\NotFound.h" />
172
    <ClInclude Include="..\wtf\NotFound.h" />
- a/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters +3 lines
Lines 501-506 a/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters_sec1
501
    <ClInclude Include="..\wtf\MetaAllocatorHandle.h">
501
    <ClInclude Include="..\wtf\MetaAllocatorHandle.h">
502
      <Filter>wtf</Filter>
502
      <Filter>wtf</Filter>
503
    </ClInclude>
503
    </ClInclude>
504
    <ClInclude Include="..\wtf\NeverDestroyed.h">
505
      <Filter>wtf</Filter>
506
    </ClInclude>
504
    <ClInclude Include="..\wtf\Noncopyable.h">
507
    <ClInclude Include="..\wtf\Noncopyable.h">
505
      <Filter>wtf</Filter>
508
      <Filter>wtf</Filter>
506
    </ClInclude>
509
    </ClInclude>
- a/Source/WTF/WTF.xcodeproj/project.pbxproj +2 lines
Lines 306-311 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec1
306
		14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaturatedArithmetic.h; sourceTree = "<group>"; };
306
		14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaturatedArithmetic.h; sourceTree = "<group>"; };
307
		1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionDispatcher.h; sourceTree = "<group>"; };
307
		1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionDispatcher.h; sourceTree = "<group>"; };
308
		1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionDispatcher.cpp; sourceTree = "<group>"; };
308
		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>"; };
309
		1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
310
		1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
310
		26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
311
		26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
311
		2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
312
		2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
Lines 690-695 a/Source/WTF/WTF.xcodeproj/project.pbxproj_sec2
690
				A8A472CD151A825B004123FF /* MetaAllocator.cpp */,
691
				A8A472CD151A825B004123FF /* MetaAllocator.cpp */,
691
				A8A472CE151A825B004123FF /* MetaAllocator.h */,
692
				A8A472CE151A825B004123FF /* MetaAllocator.h */,
692
				A8A472CF151A825B004123FF /* MetaAllocatorHandle.h */,
693
				A8A472CF151A825B004123FF /* MetaAllocatorHandle.h */,
694
				1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */,
693
				A8A472D0151A825B004123FF /* Noncopyable.h */,
695
				A8A472D0151A825B004123FF /* Noncopyable.h */,
694
				A8A472D1151A825B004123FF /* NonCopyingSort.h */,
696
				A8A472D1151A825B004123FF /* NonCopyingSort.h */,
695
				A8A472D2151A825B004123FF /* NotFound.h */,
697
				A8A472D2151A825B004123FF /* NotFound.h */,
- a/Source/WTF/wtf/Compiler.h -1 / +8 lines
Lines 65-71 a/Source/WTF/wtf/Compiler.h_sec1
65
#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
65
#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
66
#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
66
#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
67
#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_extension(cxx_reference_qualified_functions)
67
#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_extension(cxx_reference_qualified_functions)
68
69
#endif
68
#endif
70
69
71
#ifndef CLANG_PRAGMA
70
#ifndef CLANG_PRAGMA
Lines 276-281 a/Source/WTF/wtf/Compiler.h_sec2
276
#define FINAL
275
#define FINAL
277
#endif
276
#endif
278
277
278
#if COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
279
#define WTF_DELETED_FUNCTION = delete
280
#else
281
#define WTF_DELETED_FUNCTION
282
#endif
283
279
/* REFERENCED_FROM_ASM */
284
/* REFERENCED_FROM_ASM */
280
285
281
#ifndef REFERENCED_FROM_ASM
286
#ifndef REFERENCED_FROM_ASM
Lines 320-323 inline void unusedParam(T& x) { (void)x; } a/Source/WTF/wtf/Compiler.h_sec3
320
#define UNUSED_LABEL(label) UNUSED_PARAM(&& label)
325
#define UNUSED_LABEL(label) UNUSED_PARAM(&& label)
321
#endif
326
#endif
322
327
328
329
323
#endif /* WTF_Compiler_h */
330
#endif /* WTF_Compiler_h */
- a/Source/WTF/wtf/CryptographicallyRandomNumber.cpp -2 / +3 lines
Lines 30-37 a/Source/WTF/wtf/CryptographicallyRandomNumber.cpp_sec1
30
#include "config.h"
30
#include "config.h"
31
#include "CryptographicallyRandomNumber.h"
31
#include "CryptographicallyRandomNumber.h"
32
32
33
#include "NeverDestroyed.h"
33
#include "OSRandomSource.h"
34
#include "OSRandomSource.h"
34
#include "StdLibExtras.h"
35
#include "ThreadingPrimitives.h"
35
#include "ThreadingPrimitives.h"
36
36
37
namespace WTF {
37
namespace WTF {
Lines 158-164 void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length) a/Source/WTF/wtf/CryptographicallyRandomNumber.cpp_sec2
158
158
159
ARC4RandomNumberGenerator& sharedRandomNumberGenerator()
159
ARC4RandomNumberGenerator& sharedRandomNumberGenerator()
160
{
160
{
161
    DEFINE_STATIC_LOCAL(ARC4RandomNumberGenerator, randomNumberGenerator, ());
161
    static NeverDestroyed<ARC4RandomNumberGenerator> randomNumberGenerator;
162
162
    return randomNumberGenerator;
163
    return randomNumberGenerator;
163
}
164
}
164
165
- a/Source/WTF/wtf/NeverDestroyed.h +90 lines
Line 0 a/Source/WTF/wtf/NeverDestroyed.h_sec1
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
45
namespace WTF {
46
47
template<typename T> class NeverDestroyed {
48
    WTF_MAKE_NONCOPYABLE(NeverDestroyed);
49
50
public:
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
72
private:
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
88
using WTF::NeverDestroyed;
89
90
#endif // NeverDestroyed_h
- a/Source/WTF/wtf/Noncopyable.h -11 / +4 lines
Lines 23-38 a/Source/WTF/wtf/Noncopyable.h_sec1
23
23
24
#include <wtf/Compiler.h>
24
#include <wtf/Compiler.h>
25
25
26
#if COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
26
#define WTF_MAKE_NONCOPYABLE(ClassName) \
27
    #define WTF_MAKE_NONCOPYABLE(ClassName) \
27
    private: \
28
        private: \
28
        ClassName(const ClassName&) WTF_DELETED_FUNCTION; \
29
            ClassName(const ClassName&) = delete; \
29
        ClassName& operator=(const ClassName&) WTF_DELETED_FUNCTION; \
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
37
30
38
#endif // WTF_Noncopyable_h
31
#endif // WTF_Noncopyable_h
- a/Source/WTF/wtf/text/WTFString.cpp -1 / +3 lines
Lines 28-33 a/Source/WTF/wtf/text/WTFString.cpp_sec1
28
#include <wtf/DataLog.h>
28
#include <wtf/DataLog.h>
29
#include <wtf/HexNumber.h>
29
#include <wtf/HexNumber.h>
30
#include <wtf/MathExtras.h>
30
#include <wtf/MathExtras.h>
31
#include <wtf/NeverDestroyed.h>
31
#include <wtf/text/CString.h>
32
#include <wtf/text/CString.h>
32
#include <wtf/StringExtras.h>
33
#include <wtf/StringExtras.h>
33
#include <wtf/Vector.h>
34
#include <wtf/Vector.h>
Lines 1242-1248 float charactersToFloat(const UChar* data, size_t length, size_t& parsedLength) a/Source/WTF/wtf/text/WTFString.cpp_sec2
1242
1243
1243
const String& emptyString()
1244
const String& emptyString()
1244
{
1245
{
1245
    DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty()));
1246
    static NeverDestroyed<String> emptyString(StringImpl::empty());
1247
1246
    return emptyString;
1248
    return emptyString;
1247
}
1249
}
1248
1250

Return to Bug 116472