Skip to content

Commit 0b230fa

Browse files
committed
Get rid of string copy in fileWrite
1 parent 105bfa9 commit 0b230fa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Shared/mods/deathmatch/logic/luadefs/CLuaFileDefs.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ int CLuaFileDefs::fileWrite(lua_State* luaVM)
732732
CScriptArgReader argStream(luaVM);
733733
argStream.ReadUserData(pFile);
734734

735-
// Ensure we have atleast one string
735+
// Ensure we have at least one string
736736
if (!argStream.NextIsString())
737737
argStream.SetTypeError("string");
738738

@@ -745,12 +745,14 @@ int CLuaFileDefs::fileWrite(lua_State* luaVM)
745745
while (argStream.NextIsString())
746746
{
747747
// Grab argument and length
748-
SString strData;
749-
argStream.ReadString(strData);
750-
unsigned long ulDataLen = strData.length();
748+
SCharStringRef strData;
749+
argStream.ReadCharStringRef(strData);
750+
751+
if (argStream.HasErrors() || !strData.pData)
752+
continue;
751753

752754
// Write the data
753-
long lArgBytesWritten = pFile->Write(ulDataLen, strData);
755+
long lArgBytesWritten = pFile->Write(strData.uiSize, strData.pData);
754756

755757
// Did the file mysteriously disappear?
756758
if (lArgBytesWritten == -1)

0 commit comments

Comments
 (0)