Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringStatics.cpp

Issue 2655853003: Replace StringImpl::empty{16Bit}() with a static member (Closed)
Patch Set: annotate race Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2010 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 25
26 #include "wtf/text/StringStatics.h" 26 #include "wtf/text/StringStatics.h"
27 27
28 #include "wtf/DynamicAnnotations.h" 28 #include "wtf/DynamicAnnotations.h"
29 #include "wtf/StaticConstructors.h" 29 #include "wtf/StaticConstructors.h"
30 #include "wtf/text/AtomicString.h" 30 #include "wtf/text/AtomicString.h"
31 #include "wtf/text/StringImpl.h" 31 #include "wtf/text/StringImpl.h"
32 32
33 namespace WTF { 33 namespace WTF {
34 34
35 StringImpl* StringImpl::empty() {
36 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString));
37 WTF_ANNOTATE_BENIGN_RACE(&emptyString,
38 "Benign race on the reference counter of a static "
39 "string created by StringImpl::empty");
40 return &emptyString;
41 }
42
43 StringImpl* StringImpl::empty16Bit() {
44 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString16Bit));
45 WTF_ANNOTATE_BENIGN_RACE(&emptyString,
46 "Benign race on the reference counter of a static "
47 "string created by StringImpl::empty16Bit");
48 return &emptyString;
49 }
50
51 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom); 35 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom);
52 WTF_EXPORT DEFINE_GLOBAL(AtomicString, emptyAtom); 36 WTF_EXPORT DEFINE_GLOBAL(AtomicString, emptyAtom);
53 WTF_EXPORT DEFINE_GLOBAL(AtomicString, starAtom); 37 WTF_EXPORT DEFINE_GLOBAL(AtomicString, starAtom);
54 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlAtom); 38 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlAtom);
55 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlnsAtom); 39 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlnsAtom);
56 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xlinkAtom); 40 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xlinkAtom);
57 WTF_EXPORT DEFINE_GLOBAL(AtomicString, httpAtom); 41 WTF_EXPORT DEFINE_GLOBAL(AtomicString, httpAtom);
58 WTF_EXPORT DEFINE_GLOBAL(AtomicString, httpsAtom); 42 WTF_EXPORT DEFINE_GLOBAL(AtomicString, httpsAtom);
59 43
60 // This is not an AtomicString because it is unlikely to be used as an 44 // This is not an AtomicString because it is unlikely to be used as an
(...skipping 21 matching lines...) Expand all
82 const char (&characters)[charactersCount]) { 66 const char (&characters)[charactersCount]) {
83 unsigned length = charactersCount - 1; 67 unsigned length = charactersCount - 1;
84 unsigned hash = StringHasher::computeHashAndMaskTop8Bits( 68 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(
85 reinterpret_cast<const LChar*>(characters), length); 69 reinterpret_cast<const LChar*>(characters), length);
86 return adoptRef(StringImpl::createStatic(characters, length, hash)); 70 return adoptRef(StringImpl::createStatic(characters, length, hash));
87 } 71 }
88 72
89 void StringStatics::init() { 73 void StringStatics::init() {
90 DCHECK(isMainThread()); 74 DCHECK(isMainThread());
91 75
76 StringImpl::initStatics();
77
92 // FIXME: These should be allocated at compile time. 78 // FIXME: These should be allocated at compile time.
93 new (NotNull, (void*)&starAtom) AtomicString("*"); 79 new (NotNull, (void*)&starAtom) AtomicString("*");
94 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml")); 80 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml"));
95 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns")); 81 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns"));
96 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink")); 82 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink"));
97 new (NotNull, (void*)&xmlnsWithColon) String("xmlns:"); 83 new (NotNull, (void*)&xmlnsWithColon) String("xmlns:");
98 new (NotNull, (void*)&httpAtom) AtomicString(addStaticASCIILiteral("http")); 84 new (NotNull, (void*)&httpAtom) AtomicString(addStaticASCIILiteral("http"));
99 new (NotNull, (void*)&httpsAtom) AtomicString(addStaticASCIILiteral("https")); 85 new (NotNull, (void*)&httpsAtom) AtomicString(addStaticASCIILiteral("https"));
100 } 86 }
101 87
102 } // namespace WTF 88 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringMac.mm ('k') | third_party/WebKit/Source/wtf/text/StringView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698