Update code to use helper function for better readability/searching.
authordjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 21 Mar 2013 13:30:54 +0000 (13:30 +0000)
committerdjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 21 Mar 2013 13:30:54 +0000 (13:30 +0000)
Review URL: https://codereview.chromium.org/12834012

git-svn-id: http://skia.googlecode.com/svn/trunk@8287 2bbb7eff-a529-9590-31e7-b0007b416f81

src/images/SkImageDecoder_libbmp.cpp
src/images/SkImageDecoder_libico.cpp
src/ports/SkFontHost_FreeType.cpp
src/ports/SkXMLParser_expat.cpp
src/ports/SkXMLParser_tinyxml.cpp
src/ports/SkXMLPullParser_expat.cpp

index 1dcea8ad64c38bc7b8cbc06ec9a3ad6e7b5fabc6..488eddce1edb203065ce063db82e449c169db99f 100644 (file)
@@ -37,12 +37,11 @@ DEFINE_DECODER_CREATOR(BMPImageDecoder);
 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
     static const char kBmpMagic[] = { 'B', 'M' };
 
-    size_t len = stream->getLength();
+
     char buffer[sizeof(kBmpMagic)];
 
-    if (len > sizeof(kBmpMagic) &&
-            stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) &&
-            !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) {
+    if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) &&
+        !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) {
         return SkNEW(SkBMPImageDecoder);
     }
     return NULL;
index 14f575babab4162f9db3706e6350af9479692a1c..ffc59e0003e1ca6706f3ea985cab37d680fdc432 100644 (file)
@@ -75,7 +75,7 @@ static int calculateRowBytesFor8888(int w, int bitCount)
 
 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
 {
-    size_t length = stream->read(NULL, 0);
+    size_t length = stream->getLength();
     SkAutoMalloc autoMal(length);
     unsigned char* buf = (unsigned char*)autoMal.get();
     if (stream->read((void*)buf, length) != length) {
index b08aa8e6fd81928abb24611e2cc123c79965ab46..6a36f4407aa3a90cceef3e46d289593cdbff2802 100644 (file)
@@ -1333,7 +1333,7 @@ bool find_name_and_attributes(SkStream* stream, SkString* name,
         args.memory_size = stream->getLength();
     } else {
         memset(&streamRec, 0, sizeof(streamRec));
-        streamRec.size = stream->read(NULL, 0);
+        streamRec.size = stream->getLength();
         streamRec.descriptor.pointer = stream;
         streamRec.read  = sk_stream_read;
         streamRec.close = sk_stream_close;
index afc9f79fb5d73f3a8bcbd8f5807cdad1ef7496bb..3eba2fe8e0c4d0faae3e6cac99fc3b64bddd4f60 100644 (file)
@@ -113,7 +113,7 @@ bool SkXMLParser::parse(const char doc[], size_t len)
 
 bool SkXMLParser::parse(SkStream& input)
 {
-    size_t          len = input.read(NULL, 0);
+    size_t          len = input.getLength();
     SkAutoMalloc    am(len);
     char*           doc = (char*)am.get();
 
index f357592b296a0508377d4a3221b7d097ad7661c1..5f9f3a68de8d54892d16975a5d00c77ba002ebc1 100644 (file)
@@ -58,7 +58,7 @@ static bool load_buf(SkXMLParser* parser, const char buf[])
 
 bool SkXMLParser::parse(SkStream& stream)
 {
-    size_t size = stream.read(NULL, 0);
+    size_t size = stream.getLength();
 
     SkAutoMalloc    buffer(size + 1);
     char*           buf = (char*)buffer.get();
index 1d1615bcdcc78e414b40dc40a27d7717e247d0be..44a3c7f81eae0f75d3507660b2c348613df49e81 100644 (file)
@@ -152,7 +152,7 @@ bool SkXMLPullParser::onInit()
     XML_SetCharacterDataHandler(p, text_proc);
     XML_SetUserData(p, &fImpl->fData);
 
-    size_t len = fStream->read(NULL, 0);
+    size_t len = fStream->getLength();
     fImpl->fBufferLen = len;
     fImpl->fBuffer = sk_malloc_throw(len);
     fStream->rewind();