OSMLuaProcessing's Find, setWay, setNode and setRelation functions are called a lot, so avoiding copies is helpful. Avoiding these copies results in a savings of ~1.5% of the time from startup to ready-to-write-output for my usage.
I believe the changes are safe: the tag map is only accessed for the duration of setWay, setNode and setRelation, so the pointer to the map in the caller's scope is fine.
Lua never keeps pointers to external strings (or to any other object, except to C functions, which are always static). For any string that it has to keep, Lua either makes an internal copy or reuses one. Therefore, you can free or modify your buffer as soon as these functions return.
OSMLuaProcessing
'sFind
,setWay
,setNode
andsetRelation
functions are called a lot, so avoiding copies is helpful. Avoiding these copies results in a savings of ~1.5% of the time from startup to ready-to-write-output for my usage.I believe the changes are safe: the tag map is only accessed for the duration of
setWay
,setNode
andsetRelation
, so the pointer to the map in the caller's scope is fine.I believe returning a reference from
::Find
is also OK: forstd::string
, the relevant code in Kaguya is: https://github.com/satoren/kaguya/blob/9d77cad73846f5d8481f3f7e86e8c53c4891c2fb/include/kaguya/type.hpp#L654-L657, which useslua_pushlstring
to pass it to Lua code.And according to https://www.lua.org/pil/24.2.1.html: