From c682d087d9ba06d0833f1c0cb926cf4a72700654 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 Feb 2016 12:33:16 +0100 Subject: [PATCH] tag/Id3Load: optimized ID3v1 loader Use a 128 byte buffer instead of reading 10 bytes first and then 118. --- src/tag/Id3Load.cxx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tag/Id3Load.cxx b/src/tag/Id3Load.cxx index bcbac35ba..f13ed984c 100644 --- a/src/tag/Id3Load.cxx +++ b/src/tag/Id3Load.cxx @@ -95,6 +95,17 @@ ReadId3Tag(FILE *file) return UniqueId3Tag(id3_tag_parse(tag_buffer.get(), tag_size)); } +static UniqueId3Tag +ReadId3v1Tag(FILE *file) +{ + id3_byte_t buffer[ID3V1_SIZE]; + + if (fread(buffer, 1, ID3V1_SIZE, file) != ID3V1_SIZE) + return nullptr; + + return UniqueId3Tag(id3_tag_parse(buffer, ID3V1_SIZE)); +} + static UniqueId3Tag tag_id3_read(FILE *file, long offset, int whence) { @@ -141,7 +152,10 @@ tag_id3_find_from_end(FILE *stream) off_t offset = -(off_t)ID3V1_SIZE; /* Get an id3v1 tag from the end of file for later use */ - auto v1tag = tag_id3_read(stream, offset, SEEK_END); + if (fseek(stream, offset, SEEK_END) != 0) + return nullptr; + + auto v1tag = ReadId3v1Tag(stream); if (!v1tag) offset = 0;