Update code to use helper function for better readability/searching.

Review URL: https://codereview.chromium.org/12834012

git-svn-id: http://skia.googlecode.com/svn/trunk@8287 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2013-03-21 13:30:54 +00:00
parent 5dc4ca1ce6
commit 5dd45021c3
6 changed files with 8 additions and 9 deletions

View 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;

View 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) {

View 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;

View 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();

View 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();

View 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();