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

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

Issue 21437003: Remove the pointer from StringImpl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Now with placement new Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 #include "AtomicString.h" 33 #include "AtomicString.h"
34 #include "StringImpl.h" 34 #include "StringImpl.h"
35 #include "wtf/DynamicAnnotations.h" 35 #include "wtf/DynamicAnnotations.h"
36 #include "wtf/MainThread.h" 36 #include "wtf/MainThread.h"
37 #include "wtf/StaticConstructors.h" 37 #include "wtf/StaticConstructors.h"
38 38
39 namespace WTF { 39 namespace WTF {
40 40
41 StringImpl* StringImpl::empty() 41 StringImpl* StringImpl::empty()
42 { 42 {
43 // FIXME: This works around a bug in our port of PCRE, that a regular expres sion 43 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString));
44 // run on the empty string may still perform a read from the first element, and
45 // as such we need this to be a valid pointer. No code should ever be readin g
46 // from a zero length string, so this should be able to be a non-null pointe r
47 // into the zero-page.
48 // Replace this with 'reinterpret_cast<UChar*>(static_cast<intptr_t>(1))' on ce
49 // PCRE goes away.
50 static LChar emptyLCharData = 0;
51 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (&emptyLCharData, 0, ConstructS taticString));
52 WTF_ANNOTATE_BENIGN_RACE(&emptyString, "Benign race on StringImpl::emptyStri ng reference counter"); 44 WTF_ANNOTATE_BENIGN_RACE(&emptyString, "Benign race on StringImpl::emptyStri ng reference counter");
53 return &emptyString; 45 return &emptyString;
54 } 46 }
55 47
56 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom) 48 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom)
57 WTF_EXPORT DEFINE_GLOBAL(AtomicString, emptyAtom) 49 WTF_EXPORT DEFINE_GLOBAL(AtomicString, emptyAtom)
58 WTF_EXPORT DEFINE_GLOBAL(AtomicString, textAtom) 50 WTF_EXPORT DEFINE_GLOBAL(AtomicString, textAtom)
59 WTF_EXPORT DEFINE_GLOBAL(AtomicString, commentAtom) 51 WTF_EXPORT DEFINE_GLOBAL(AtomicString, commentAtom)
60 WTF_EXPORT DEFINE_GLOBAL(AtomicString, starAtom) 52 WTF_EXPORT DEFINE_GLOBAL(AtomicString, starAtom)
61 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlAtom) 53 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlAtom)
62 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlnsAtom) 54 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlnsAtom)
63 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xlinkAtom) 55 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xlinkAtom)
64 56
65 NEVER_INLINE unsigned StringImpl::hashSlowCase() const 57 NEVER_INLINE unsigned StringImpl::hashSlowCase() const
66 { 58 {
67 if (is8Bit()) 59 if (is8Bit())
68 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data8, m_length)); 60 setHash(StringHasher::computeHashAndMaskTop8Bits(characters8(), m_length ));
69 else 61 else
70 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data16, m_length)); 62 setHash(StringHasher::computeHashAndMaskTop8Bits(characters16(), m_lengt h));
71 return existingHash(); 63 return existingHash();
72 } 64 }
73 65
74 void AtomicString::init() 66 void AtomicString::init()
75 { 67 {
76 ASSERT(isMainThread()); 68 ASSERT(isMainThread());
77 69
78 new (NotNull, (void*)&nullAtom) AtomicString; 70 new (NotNull, (void*)&nullAtom) AtomicString;
79 new (NotNull, (void*)&emptyAtom) AtomicString(""); 71 new (NotNull, (void*)&emptyAtom) AtomicString("");
80 } 72 }
81 73
82 void StringStatics::init() 74 void StringStatics::init()
83 { 75 {
84 ASSERT(isMainThread()); 76 ASSERT(isMainThread());
85 77
86 // FIXME: These should be allocated at compile time. 78 // FIXME: These should be allocated at compile time.
87 new (NotNull, (void*)&textAtom) AtomicString("#text", AtomicString::Construc tFromLiteral); 79 new (NotNull, (void*)&textAtom) AtomicString("#text", AtomicString::Construc tFromLiteral);
88 new (NotNull, (void*)&commentAtom) AtomicString("#comment", AtomicString::Co nstructFromLiteral); 80 new (NotNull, (void*)&commentAtom) AtomicString("#comment", AtomicString::Co nstructFromLiteral);
89 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFro mLiteral); 81 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFro mLiteral);
90 new (NotNull, (void*)&xmlAtom) AtomicString("xml", AtomicString::ConstructFr omLiteral); 82 new (NotNull, (void*)&xmlAtom) AtomicString("xml", AtomicString::ConstructFr omLiteral);
91 new (NotNull, (void*)&xmlnsAtom) AtomicString("xmlns", AtomicString::Constru ctFromLiteral); 83 new (NotNull, (void*)&xmlnsAtom) AtomicString("xmlns", AtomicString::Constru ctFromLiteral);
92 new (NotNull, (void*)&xlinkAtom) AtomicString("xlink", AtomicString::Constru ctFromLiteral); 84 new (NotNull, (void*)&xlinkAtom) AtomicString("xlink", AtomicString::Constru ctFromLiteral);
93 } 85 }
94 86
95 } 87 }
OLDNEW
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698