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

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

Issue 2373983006: reflow comments in wtf/text (Closed)
Patch Set: Created 4 years, 2 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) 2006, 2009, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2009, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (!isMainThread()) { 89 if (!isMainThread()) {
90 internal::callOnMainThread(&deallocateOnMainThread, header); 90 internal::callOnMainThread(&deallocateOnMainThread, header);
91 } else { 91 } else {
92 underlyingString->deref(); // Balanced by call to ref in allocate above. 92 underlyingString->deref(); // Balanced by call to ref in allocate above.
93 WTF::Partitions::fastFree(header); 93 WTF::Partitions::fastFree(header);
94 } 94 }
95 } 95 }
96 } 96 }
97 97
98 static CFIndex preferredSize(CFIndex size, CFOptionFlags, void*) { 98 static CFIndex preferredSize(CFIndex size, CFOptionFlags, void*) {
99 // FIXME: If FastMalloc provided a "good size" callback, we'd want to use it h ere. 99 // FIXME: If FastMalloc provided a "good size" callback, we'd want to use it
100 // Note that this optimization would help performance for strings created with the 100 // here. Note that this optimization would help performance for strings
101 // allocator that are mutable, and those typically are only created by callers who 101 // created with the allocator that are mutable, and those typically are only
102 // make a new string using the old string's allocator, such as some of the cal l 102 // created by callers who make a new string using the old string's allocator,
103 // sites in CFURL. 103 // such as some of the call sites in CFURL.
104 return size; 104 return size;
105 } 105 }
106 106
107 static CFAllocatorRef create() { 107 static CFAllocatorRef create() {
108 CFAllocatorContext context = { 108 CFAllocatorContext context = {
109 0, 0, retain, release, copyDescription, 109 0, 0, retain, release, copyDescription,
110 allocate, reallocate, deallocate, preferredSize}; 110 allocate, reallocate, deallocate, preferredSize};
111 return CFAllocatorCreate(0, &context); 111 return CFAllocatorCreate(0, &context);
112 } 112 }
113 113
(...skipping 10 matching lines...) Expand all
124 if (!m_length || !isMainThread()) { 124 if (!m_length || !isMainThread()) {
125 if (is8Bit()) 125 if (is8Bit())
126 return adoptCF(CFStringCreateWithBytes( 126 return adoptCF(CFStringCreateWithBytes(
127 0, reinterpret_cast<const UInt8*>(characters8()), m_length, 127 0, reinterpret_cast<const UInt8*>(characters8()), m_length,
128 kCFStringEncodingISOLatin1, false)); 128 kCFStringEncodingISOLatin1, false));
129 return adoptCF(CFStringCreateWithCharacters( 129 return adoptCF(CFStringCreateWithCharacters(
130 0, reinterpret_cast<const UniChar*>(characters16()), m_length)); 130 0, reinterpret_cast<const UniChar*>(characters16()), m_length));
131 } 131 }
132 CFAllocatorRef allocator = StringWrapperCFAllocator::allocator(); 132 CFAllocatorRef allocator = StringWrapperCFAllocator::allocator();
133 133
134 // Put pointer to the StringImpl in a global so the allocator can store it wit h the CFString. 134 // Put pointer to the StringImpl in a global so the allocator can store it
135 // with the CFString.
135 ASSERT(!StringWrapperCFAllocator::currentString); 136 ASSERT(!StringWrapperCFAllocator::currentString);
136 StringWrapperCFAllocator::currentString = this; 137 StringWrapperCFAllocator::currentString = this;
137 138
138 CFStringRef string; 139 CFStringRef string;
139 if (is8Bit()) 140 if (is8Bit())
140 string = CFStringCreateWithBytesNoCopy( 141 string = CFStringCreateWithBytesNoCopy(
141 allocator, reinterpret_cast<const UInt8*>(characters8()), m_length, 142 allocator, reinterpret_cast<const UInt8*>(characters8()), m_length,
142 kCFStringEncodingISOLatin1, false, kCFAllocatorNull); 143 kCFStringEncodingISOLatin1, false, kCFAllocatorNull);
143 else 144 else
144 string = CFStringCreateWithCharactersNoCopy( 145 string = CFStringCreateWithCharactersNoCopy(
145 allocator, reinterpret_cast<const UniChar*>(characters16()), m_length, 146 allocator, reinterpret_cast<const UniChar*>(characters16()), m_length,
146 kCFAllocatorNull); 147 kCFAllocatorNull);
147 // CoreFoundation might not have to allocate anything, we clear currentString in case we did not execute allocate(). 148 // CoreFoundation might not have to allocate anything, we clear currentString
149 // in case we did not execute allocate().
148 StringWrapperCFAllocator::currentString = 0; 150 StringWrapperCFAllocator::currentString = 0;
149 151
150 return adoptCF(string); 152 return adoptCF(string);
151 } 153 }
152 154
153 // On StringImpl creation we could check if the allocator is the StringWrapperCF Allocator. 155 // On StringImpl creation we could check if the allocator is the
154 // If it is, then we could find the original StringImpl and just return that. Bu t to 156 // StringWrapperCFAllocator. If it is, then we could find the original
155 // do that we'd have to compute the offset from CFStringRef to the allocated blo ck; 157 // StringImpl and just return that. But to do that we'd have to compute the
dcheng 2016/10/01 03:06:14 Out of curiosity, why are the spaces inconsistent
Nico 2016/10/01 16:42:24 I used vim's gq to reflow comments. The . was at e
156 // the CFStringRef is *not* at the start of an allocated block. Testing shows 10 00x 158 // offset from CFStringRef to the allocated block; the CFStringRef is *not* at
157 // more calls to createCFString than calls to the create functions with the appr opriate 159 // the start of an allocated block. Testing shows 1000x more calls to
160 // createCFString than calls to the create functions with the appropriate
158 // allocator, so it's probably not urgent optimize that case. 161 // allocator, so it's probably not urgent optimize that case.
159 162
160 } // namespace WTF 163 } // namespace WTF
161 164
162 #endif // OS(MACOSX) 165 #endif // OS(MACOSX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698