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

Side by Side Diff: src/images/SkStreamHelpers.cpp

Issue 23330002: Avoid getLength in ico decoder. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. 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 | « src/images/SkStreamHelpers.h ('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
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkStream.h"
9 #include "SkStreamHelpers.h"
10 #include "SkTypes.h"
11
12 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
13 SkASSERT(storage != NULL);
14 SkASSERT(stream != NULL);
15
16 if (stream->hasLength()) {
17 const size_t length = stream->getLength();
18 void* dst = storage->reset(length);
19 if (stream->read(dst, length) != length) {
20 return 0;
21 }
22 return length;
23 }
24
25 SkDynamicMemoryWStream tempStream;
26 // Arbitrary buffer size.
27 const size_t bufferSize = 256 * 1024; // 256KB
28 char buffer[bufferSize];
29 SkDEBUGCODE(size_t debugLength = 0;)
30 do {
31 size_t bytesRead = stream->read(buffer, bufferSize);
32 tempStream.write(buffer, bytesRead);
33 SkDEBUGCODE(debugLength += bytesRead);
34 SkASSERT(tempStream.bytesWritten() == debugLength);
35 } while (!stream->isAtEnd());
36 const size_t length = tempStream.bytesWritten();
37 void* dst = storage->reset(length);
38 tempStream.copyTo(dst);
39 return length;
40 }
OLDNEW
« no previous file with comments | « src/images/SkStreamHelpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698