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

Side by Side Diff: src/core/SkStream.cpp

Issue 706063002: for X in {Dec,BigDec,Scalar}, SkWStream::write"X"AsText no longer mallocs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 bool SkWStream::writeText(const char text[]) 82 bool SkWStream::writeText(const char text[])
83 { 83 {
84 SkASSERT(text); 84 SkASSERT(text);
85 return this->write(text, strlen(text)); 85 return this->write(text, strlen(text));
86 } 86 }
87 87
88 bool SkWStream::writeDecAsText(int32_t dec) 88 bool SkWStream::writeDecAsText(int32_t dec)
89 { 89 {
90 SkString tmp; 90 char buffer[SkStrAppendS32_MaxSize];
reed1 2014/11/06 21:45:09 does the buffer need to be this const + 1, to have
hal.canary 2014/11/06 22:26:30 SkWStream::write(void*, size_t) doesn't need a ter
reed1 2014/11/07 14:52:28 Ah, right. I'll add some dox so I can remind myse
91 tmp.appendS32(dec); 91 char* stop = SkStrAppendS32(buffer, dec);
92 return this->write(tmp.c_str(), tmp.size()); 92 return this->write(buffer, stop - buffer);
93 } 93 }
94 94
95 bool SkWStream::writeBigDecAsText(int64_t dec, int minDigits) 95 bool SkWStream::writeBigDecAsText(int64_t dec, int minDigits)
96 { 96 {
97 SkString tmp; 97 char buffer[SkStrAppendU64_MaxSize];
98 tmp.appendS64(dec, minDigits); 98 char* stop = SkStrAppendU64(buffer, dec, minDigits);
99 return this->write(tmp.c_str(), tmp.size()); 99 return this->write(buffer, stop - buffer);
100 } 100 }
101 101
102 bool SkWStream::writeHexAsText(uint32_t hex, int digits) 102 bool SkWStream::writeHexAsText(uint32_t hex, int digits)
103 { 103 {
104 SkString tmp; 104 SkString tmp;
105 tmp.appendHex(hex, digits); 105 tmp.appendHex(hex, digits);
106 return this->write(tmp.c_str(), tmp.size()); 106 return this->write(tmp.c_str(), tmp.size());
107 } 107 }
108 108
109 bool SkWStream::writeScalarAsText(SkScalar value) 109 bool SkWStream::writeScalarAsText(SkScalar value)
110 { 110 {
111 SkString tmp; 111 char buffer[SkStrAppendScalar_MaxSize];
112 tmp.appendScalar(value); 112 char* stop = SkStrAppendScalar(buffer, value);
113 return this->write(tmp.c_str(), tmp.size()); 113 return this->write(buffer, stop - buffer);
114 } 114 }
115 115
116 bool SkWStream::write8(U8CPU value) { 116 bool SkWStream::write8(U8CPU value) {
117 uint8_t v = SkToU8(value); 117 uint8_t v = SkToU8(value);
118 return this->write(&v, 1); 118 return this->write(&v, 1);
119 } 119 }
120 120
121 bool SkWStream::write16(U16CPU value) { 121 bool SkWStream::write16(U16CPU value) {
122 uint16_t v = SkToU16(value); 122 uint16_t v = SkToU16(value);
123 return this->write(&v, 2); 123 return this->write(&v, 2);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 SkDynamicMemoryWStream tempStream; 902 SkDynamicMemoryWStream tempStream;
903 const size_t bufferSize = 4096; 903 const size_t bufferSize = 4096;
904 char buffer[bufferSize]; 904 char buffer[bufferSize];
905 do { 905 do {
906 size_t bytesRead = stream->read(buffer, bufferSize); 906 size_t bytesRead = stream->read(buffer, bufferSize);
907 tempStream.write(buffer, bytesRead); 907 tempStream.write(buffer, bytesRead);
908 } while (!stream->isAtEnd()); 908 } while (!stream->isAtEnd());
909 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, 909 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
910 // cheaper than copying to SkData 910 // cheaper than copying to SkData
911 } 911 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698