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

Side by Side Diff: Source/platform/graphics/Color.cpp

Issue 482753002: Use StringBuilder::appendLiteral() / StringBuilder::append(char) when possible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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/platform/animation/TimingFunction.cpp ('k') | Source/platform/mhtml/MHTMLArchive.cpp » ('j') | 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) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return parseHexColor(name.characters8() + 1, name.length() - 1, m_color) ; 187 return parseHexColor(name.characters8() + 1, name.length() - 1, m_color) ;
188 return parseHexColor(name.characters16() + 1, name.length() - 1, m_color); 188 return parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
189 } 189 }
190 190
191 String Color::serializedAsCSSComponentValue() const 191 String Color::serializedAsCSSComponentValue() const
192 { 192 {
193 StringBuilder result; 193 StringBuilder result;
194 result.reserveCapacity(32); 194 result.reserveCapacity(32);
195 bool colorHasAlpha = hasAlpha(); 195 bool colorHasAlpha = hasAlpha();
196 if (colorHasAlpha) 196 if (colorHasAlpha)
197 result.append("rgba(", 5); 197 result.appendLiteral("rgba(");
198 else 198 else
199 result.append("rgb(", 4); 199 result.appendLiteral("rgb(");
200 200
201 result.appendNumber(static_cast<unsigned char>(red())); 201 result.appendNumber(static_cast<unsigned char>(red()));
202 result.append(", ", 2); 202 result.appendLiteral(", ");
203 203
204 result.appendNumber(static_cast<unsigned char>(green())); 204 result.appendNumber(static_cast<unsigned char>(green()));
205 result.append(", ", 2); 205 result.appendLiteral(", ");
206 206
207 result.appendNumber(static_cast<unsigned char>(blue())); 207 result.appendNumber(static_cast<unsigned char>(blue()));
208 if (colorHasAlpha) { 208 if (colorHasAlpha) {
209 result.append(", ", 2); 209 result.appendLiteral(", ");
210 210
211 NumberToStringBuffer buffer; 211 NumberToStringBuffer buffer;
212 const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f, 6, buffer, true); 212 const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f, 6, buffer, true);
213 result.append(alphaString, strlen(alphaString)); 213 result.append(alphaString, strlen(alphaString));
214 } 214 }
215 215
216 result.append(')'); 216 result.append(')');
217 return result.toString(); 217 return result.toString();
218 } 218 }
219 219
220 String Color::serialized() const 220 String Color::serialized() const
221 { 221 {
222 if (!hasAlpha()) { 222 if (!hasAlpha()) {
223 StringBuilder builder; 223 StringBuilder builder;
224 builder.reserveCapacity(7); 224 builder.reserveCapacity(7);
225 builder.append('#'); 225 builder.append('#');
226 appendByteAsHex(red(), builder, Lowercase); 226 appendByteAsHex(red(), builder, Lowercase);
227 appendByteAsHex(green(), builder, Lowercase); 227 appendByteAsHex(green(), builder, Lowercase);
228 appendByteAsHex(blue(), builder, Lowercase); 228 appendByteAsHex(blue(), builder, Lowercase);
229 return builder.toString(); 229 return builder.toString();
230 } 230 }
231 231
232 StringBuilder result; 232 StringBuilder result;
233 result.reserveCapacity(28); 233 result.reserveCapacity(28);
234 const char commaSpace[] = ", ";
235 const char rgbaParen[] = "rgba(";
236 234
237 result.append(rgbaParen, 5); 235 result.appendLiteral("rgba(");
238 result.appendNumber(red()); 236 result.appendNumber(red());
239 result.append(commaSpace, 2); 237 result.appendLiteral(", ");
240 result.appendNumber(green()); 238 result.appendNumber(green());
241 result.append(commaSpace, 2); 239 result.appendLiteral(", ");
242 result.appendNumber(blue()); 240 result.appendNumber(blue());
243 result.append(commaSpace, 2); 241 result.appendLiteral(", ");
244 242
245 if (!alpha()) 243 if (!alpha())
246 result.append('0'); 244 result.append('0');
247 else { 245 else {
248 result.append(Decimal::fromDouble(alpha() / 255.0).toString()); 246 result.append(Decimal::fromDouble(alpha() / 255.0).toString());
249 } 247 }
250 248
251 result.append(')'); 249 result.append(')');
252 return result.toString(); 250 return result.toString();
253 } 251 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 (color.green() * alpha + 254) / 255, 456 (color.green() * alpha + 254) / 255,
459 (color.blue() * alpha + 254) / 255, 457 (color.blue() * alpha + 254) / 255,
460 alpha).rgb(); 458 alpha).rgb();
461 } else 459 } else
462 pixelColor = color.rgb(); 460 pixelColor = color.rgb();
463 461
464 return pixelColor; 462 return pixelColor;
465 } 463 }
466 464
467 } // namespace blink 465 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/animation/TimingFunction.cpp ('k') | Source/platform/mhtml/MHTMLArchive.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698