tag/Id3Load: don't seek twice in tag_id3_read()
Copy the query buffer to the allocated buffer, and read only the remaining data.
This commit is contained in:
parent
2ef8403bfa
commit
84fe3bfa87
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <id3tag.h>
|
#include <id3tag.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static constexpr Domain id3_domain("id3");
|
static constexpr Domain id3_domain("id3");
|
||||||
@ -77,12 +79,19 @@ tag_id3_read(FILE *stream, long offset, int whence)
|
|||||||
return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size));
|
return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size));
|
||||||
|
|
||||||
std::unique_ptr<id3_byte_t[]> tag_buffer(new id3_byte_t[tag_size]);
|
std::unique_ptr<id3_byte_t[]> tag_buffer(new id3_byte_t[tag_size]);
|
||||||
int tag_buffer_size = fill_buffer(tag_buffer.get(), tag_size,
|
|
||||||
stream, offset, whence);
|
/* copy the start of the tag we already have to the allocated
|
||||||
if (tag_buffer_size < tag_size)
|
buffer */
|
||||||
|
id3_byte_t *end = std::copy_n(query_buffer, query_buffer_size,
|
||||||
|
tag_buffer.get());
|
||||||
|
|
||||||
|
/* now read the remaining bytes */
|
||||||
|
const size_t remaining = tag_size - query_buffer_size;
|
||||||
|
const size_t nbytes = fread(end, 1, remaining, stream);
|
||||||
|
if (nbytes != remaining)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return UniqueId3Tag(id3_tag_parse(tag_buffer.get(), tag_buffer_size));
|
return UniqueId3Tag(id3_tag_parse(tag_buffer.get(), tag_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniqueId3Tag
|
static UniqueId3Tag
|
||||||
|
Loading…
Reference in New Issue
Block a user