Skip to content

Commit d83ddf8

Browse files
committed
Fix useless allocations in VM FileSystem functionality
1 parent 42068e1 commit d83ddf8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/engine/framework/CommonVMServices.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ namespace VM {
273273
case QVM_COMMON_FS_READ:
274274
IPC::HandleMsg<FSReadMsg>(channel, std::move(reader), [this](int handle, int len, std::string& res, int& ret) {
275275
FS_CheckOwnership(handle, fileOwnership);
276-
std::unique_ptr<char[]> buffer(new char[len]);
277-
ret = FS_Read(buffer.get(), len, handle);
278-
res.assign(buffer.get(), ret >= 0 ? ret : 0);
276+
res.resize( len );
277+
ret = FS_Read( &res[0], len, handle );
278+
279+
res.resize( ret );
280+
res.shrink_to_fit();
279281
});
280282
break;
281283

@@ -315,17 +317,15 @@ namespace VM {
315317

316318
case QVM_COMMON_FS_GET_FILE_LIST:
317319
IPC::HandleMsg<FSGetFileListMsg>(channel, std::move(reader), [this](const std::string& path, std::string extension, int len, int& intRes, std::string& res) {
318-
std::unique_ptr<char[]> buffer(new char[len]);
319-
intRes = FS_GetFileList(path.c_str(), extension.c_str(), buffer.get(), len);
320-
res.assign(buffer.get(), len);
320+
res.resize( len );
321+
intRes = FS_GetFileList(path.c_str(), extension.c_str(), &res[0], len);
321322
});
322323
break;
323324

324325
case QVM_COMMON_FS_GET_FILE_LIST_RECURSIVE:
325326
IPC::HandleMsg<FSGetFileListRecursiveMsg>(channel, std::move(reader), [this](const std::string& path, std::string extension, int len, int& intRes, std::string& res) {
326-
std::unique_ptr<char[]> buffer(new char[len]);
327-
intRes = FS_GetFileListRecursive(path.c_str(), extension.c_str(), buffer.get(), len);
328-
res.assign(buffer.get(), len);
327+
res.resize( len );
328+
intRes = FS_GetFileListRecursive(path.c_str(), extension.c_str(), &res[0], len);
329329
});
330330
break;
331331

0 commit comments

Comments
 (0)