diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-29 18:31:00 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-29 18:31:00 +0300 |
commit | 7132f71cf010e4f13eb27c1a24d8878aa984b43f (patch) | |
tree | 330ad08a5ae15d0f4dc2d13461de1d5a47a69fe6 /src/fs/virtfs/virtfszip.cpp | |
parent | d9c0d1c3b2800b0c995393426b65a031203ca2f0 (diff) | |
download | mv-7132f71cf010e4f13eb27c1a24d8878aa984b43f.tar.gz mv-7132f71cf010e4f13eb27c1a24d8878aa984b43f.tar.bz2 mv-7132f71cf010e4f13eb27c1a24d8878aa984b43f.tar.xz mv-7132f71cf010e4f13eb27c1a24d8878aa984b43f.zip |
Remove extra memory copy in VirtFs::loadFile.
Also add const into VirtFs::loadFile.
Diffstat (limited to 'src/fs/virtfs/virtfszip.cpp')
-rw-r--r-- | src/fs/virtfs/virtfszip.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp index 62ad591ae..d344a4c64 100644 --- a/src/fs/virtfs/virtfszip.cpp +++ b/src/fs/virtfs/virtfszip.cpp @@ -336,9 +336,9 @@ namespace VirtFsZip return file->mPos >= file->mSize; } - char *loadFile(VirtFsEntry *restrict const entry, - const std::string &restrict filename, - int &restrict fileSize) + const char *loadFile(VirtFsEntry *restrict const entry, + const std::string &restrict filename, + int &restrict fileSize) { VirtZipEntry *const zipEntry = static_cast<VirtZipEntry*>(entry); FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator, @@ -357,12 +357,7 @@ namespace VirtFsZip filename.c_str()); fileSize = header->uncompressSize; - // Allocate memory and load the file - char *restrict const buffer = new char[fileSize]; - if (fileSize > 0) - buffer[fileSize - 1] = 0; - memcpy(buffer, buf, fileSize); - return buffer; + return reinterpret_cast<const char*>(buf); } } return nullptr; |