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

Side by Side Diff: src/pdf/SkPDFTypes.cpp

Issue 2099463002: SkPDF: alloc less memory for strings (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-06-23 (Thursday) 16:23:34 EDT Created 4 years, 5 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 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDeflate.h" 8 #include "SkDeflate.h"
9 #include "SkPDFTypes.h" 9 #include "SkPDFTypes.h"
10 #include "SkPDFUtils.h" 10 #include "SkPDFUtils.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 char buffer[3] = {'#', '\0', '\0'}; 103 char buffer[3] = {'#', '\0', '\0'};
104 buffer[1] = kHex[(*n >> 4) & 0xF]; 104 buffer[1] = kHex[(*n >> 4) & 0xF];
105 buffer[2] = kHex[*n & 0xF]; 105 buffer[2] = kHex[*n & 0xF];
106 o->write(buffer, sizeof(buffer)); 106 o->write(buffer, sizeof(buffer));
107 } else { 107 } else {
108 o->write(n, 1); 108 o->write(n, 1);
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 static void write_string(SkWStream* o, const SkString& s) {
114 o->write(s.c_str(), s.size());
115 }
116
117 static SkString format_string(const SkString& s) {
118 return SkPDFUtils::FormatString(s.c_str(), s.size());
119 }
120
121 static SkString format_string(const char* s) {
122 return SkPDFUtils::FormatString(s, strlen(s));
123 }
124
125 void SkPDFUnion::emitObject(SkWStream* stream, 113 void SkPDFUnion::emitObject(SkWStream* stream,
126 const SkPDFObjNumMap& objNumMap, 114 const SkPDFObjNumMap& objNumMap,
127 const SkPDFSubstituteMap& substitutes) const { 115 const SkPDFSubstituteMap& substitutes) const {
128 switch (fType) { 116 switch (fType) {
129 case Type::kInt: 117 case Type::kInt:
130 stream->writeDecAsText(fIntValue); 118 stream->writeDecAsText(fIntValue);
131 return; 119 return;
132 case Type::kBool: 120 case Type::kBool:
133 stream->writeText(fBoolValue ? "true" : "false"); 121 stream->writeText(fBoolValue ? "true" : "false");
134 return; 122 return;
135 case Type::kScalar: 123 case Type::kScalar:
136 SkPDFUtils::AppendScalar(fScalarValue, stream); 124 SkPDFUtils::AppendScalar(fScalarValue, stream);
137 return; 125 return;
138 case Type::kName: 126 case Type::kName:
139 stream->writeText("/"); 127 stream->writeText("/");
140 SkASSERT(is_valid_name(fStaticString)); 128 SkASSERT(is_valid_name(fStaticString));
141 stream->writeText(fStaticString); 129 stream->writeText(fStaticString);
142 return; 130 return;
143 case Type::kString: 131 case Type::kString:
144 SkASSERT(fStaticString); 132 SkASSERT(fStaticString);
145 write_string(stream, format_string(fStaticString)); 133 SkPDFUtils::WriteString(stream, fStaticString,
134 strlen(fStaticString));
146 return; 135 return;
147 case Type::kNameSkS: 136 case Type::kNameSkS:
148 stream->writeText("/"); 137 stream->writeText("/");
149 write_name_escaped(stream, pun(fSkString)->c_str()); 138 write_name_escaped(stream, pun(fSkString)->c_str());
150 return; 139 return;
151 case Type::kStringSkS: 140 case Type::kStringSkS:
152 write_string(stream, format_string(*pun(fSkString))); 141 SkPDFUtils::WriteString(stream, pun(fSkString)->c_str(),
142 pun(fSkString)->size());
153 return; 143 return;
154 case Type::kObjRef: 144 case Type::kObjRef:
155 stream->writeDecAsText(objNumMap.getObjectNumber( 145 stream->writeDecAsText(objNumMap.getObjectNumber(
156 substitutes.getSubstitute(fObject))); 146 substitutes.getSubstitute(fObject)));
157 stream->writeText(" 0 R"); // Generation number is always 0. 147 stream->writeText(" 0 R"); // Generation number is always 0.
158 return; 148 return;
159 case Type::kObject: 149 case Type::kObject:
160 fObject->emitObject(stream, objNumMap, substitutes); 150 fObject->emitObject(stream, objNumMap, substitutes);
161 return; 151 return;
162 default: 152 default:
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 563
574 void SkPDFImageDumpStats() { 564 void SkPDFImageDumpStats() {
575 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" 565 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n"
576 "total PDF jpeg images: %d\n" 566 "total PDF jpeg images: %d\n"
577 "total PDF regular images: %d\n", 567 "total PDF regular images: %d\n",
578 gDrawImageCalls.load(), 568 gDrawImageCalls.load(),
579 gJpegImageObjects.load(), 569 gJpegImageObjects.load(),
580 gRegularImageObjects.load()); 570 gRegularImageObjects.load());
581 } 571 }
582 #endif // SK_PDF_IMAGE_STATS 572 #endif // SK_PDF_IMAGE_STATS
OLDNEW
« src/pdf/SkPDFDevice.cpp ('K') | « src/pdf/SkPDFDevice.cpp ('k') | src/pdf/SkPDFUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698