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

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

Issue 1640793002: Consolidate SkStream copying methods (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 const size_t bufferSize = 4096; 893 if (!SkStreamCopy(&tempStream, stream)) {
894 char buffer[bufferSize]; 894 return nullptr;
895 do { 895 }
896 size_t bytesRead = stream->read(buffer, bufferSize);
897 tempStream.write(buffer, bytesRead);
898 } while (!stream->isAtEnd());
899 return tempStream.copyToData(); 896 return tempStream.copyToData();
900 } 897 }
901 898
902 bool SkStreamCopy(SkWStream* out, SkStream* input) { 899 bool SkStreamCopy(SkWStream* out, SkStream* input) {
903 const char* base = static_cast<const char*>(input->getMemoryBase()); 900 const char* base = static_cast<const char*>(input->getMemoryBase());
904 if (base && input->hasPosition() && input->hasLength()) { 901 if (base && input->hasPosition() && input->hasLength()) {
905 // Shortcut that avoids the while loop. 902 // Shortcut that avoids the while loop.
906 size_t position = input->getPosition(); 903 size_t position = input->getPosition();
907 size_t length = input->getLength(); 904 size_t length = input->getLength();
908 SkASSERT(length >= position); 905 SkASSERT(length >= position);
909 return out->write(&base[position], length - position); 906 return out->write(&base[position], length - position);
910 } 907 }
911 char scratch[4096]; 908 char scratch[4096];
912 size_t count; 909 size_t count;
913 while (true) { 910 while (true) {
914 count = input->read(scratch, sizeof(scratch)); 911 count = input->read(scratch, sizeof(scratch));
915 if (0 == count) { 912 if (0 == count) {
916 return true; 913 return true;
917 } 914 }
918 if (!out->write(scratch, count)) { 915 if (!out->write(scratch, count)) {
919 return false; 916 return false;
920 } 917 }
921 } 918 }
922 } 919 }
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