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

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

Issue 1641853002: Revert of Consolidate SkStream copying methods (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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
« 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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 883
884 // Declared in SkStreamPriv.h: 884 // Declared in SkStreamPriv.h:
885 SkData* SkCopyStreamToData(SkStream* stream) { 885 SkData* SkCopyStreamToData(SkStream* stream) {
886 SkASSERT(stream != nullptr); 886 SkASSERT(stream != nullptr);
887 887
888 if (stream->hasLength()) { 888 if (stream->hasLength()) {
889 return SkData::NewFromStream(stream, stream->getLength()); 889 return SkData::NewFromStream(stream, stream->getLength());
890 } 890 }
891 891
892 SkDynamicMemoryWStream tempStream; 892 SkDynamicMemoryWStream tempStream;
893 if (!SkStreamCopy(&tempStream, stream)) { 893 const size_t bufferSize = 4096;
894 return nullptr; 894 char buffer[bufferSize];
895 } 895 do {
896 size_t bytesRead = stream->read(buffer, bufferSize);
897 tempStream.write(buffer, bytesRead);
898 } while (!stream->isAtEnd());
896 return tempStream.copyToData(); 899 return tempStream.copyToData();
897 } 900 }
898 901
899 bool SkStreamCopy(SkWStream* out, SkStream* input) { 902 bool SkStreamCopy(SkWStream* out, SkStream* input) {
900 const char* base = static_cast<const char*>(input->getMemoryBase()); 903 const char* base = static_cast<const char*>(input->getMemoryBase());
901 if (base && input->hasPosition() && input->hasLength()) { 904 if (base && input->hasPosition() && input->hasLength()) {
902 // Shortcut that avoids the while loop. 905 // Shortcut that avoids the while loop.
903 size_t position = input->getPosition(); 906 size_t position = input->getPosition();
904 size_t length = input->getLength(); 907 size_t length = input->getLength();
905 SkASSERT(length >= position); 908 SkASSERT(length >= position);
906 return out->write(&base[position], length - position); 909 return out->write(&base[position], length - position);
907 } 910 }
908 char scratch[4096]; 911 char scratch[4096];
909 size_t count; 912 size_t count;
910 while (true) { 913 while (true) {
911 count = input->read(scratch, sizeof(scratch)); 914 count = input->read(scratch, sizeof(scratch));
912 if (0 == count) { 915 if (0 == count) {
913 return true; 916 return true;
914 } 917 }
915 if (!out->write(scratch, count)) { 918 if (!out->write(scratch, count)) {
916 return false; 919 return false;
917 } 920 }
918 } 921 }
919 } 922 }
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