The current code creates an SkFILEStream and then reads all the bytes
from it into an SkData. Instead, let the SkData just mmap the file.
Change-Id: I79e3550a84e6f54ccbbd7284f5cda81ce1fa9221
Reviewed-on: https://skia-review.googlesource.com/9877
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
sk_sp<SkData> GetResourceAsData(const char* resource) {
SkString resourcePath = GetResourcePath(resource);
- std::unique_ptr<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
- if (!stream->isValid()) {
- SkDebugf("Resource %s not found.\n", resource);
- return nullptr;
- }
- size_t bytes = stream->getLength();
- sk_sp<SkData> data = SkData::MakeUninitialized(bytes);
- stream->read(data->writable_data(), bytes);
- return data;
+ return SkData::MakeFromFileName(resourcePath.c_str());
}
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {