mirror of
https://github.com/nmap/nmap.git
synced 2025-12-25 08:59:01 +00:00
Clean up string concatenations
Building a string with var = var .. "something" has miserable time complexities. This commit cleans up a lot of that in scripts, focusing on packing of data with bin.pack and concatenations within loops. Additionally, a few instances were replaced with string.rep
This commit is contained in:
@@ -94,16 +94,16 @@ local function createKMLFile(filename, coords)
|
||||
local header = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><LineString><coordinates>\r\n'
|
||||
local footer = '</coordinates></LineString><Style><LineStyle><color>#ff0000ff</color></LineStyle></Style></Placemark></Document></kml>'
|
||||
|
||||
local output = ""
|
||||
local output = {}
|
||||
for _, coord in ipairs(coords) do
|
||||
output = output .. ("%s,%s, 0.\r\n"):format(coord.lon, coord.lat)
|
||||
output[#output+1] = ("%s,%s, 0.\r\n"):format(coord.lon, coord.lat)
|
||||
end
|
||||
|
||||
local f = io.open(filename, "w")
|
||||
if ( not(f) ) then
|
||||
return false, "Failed to create KML file"
|
||||
end
|
||||
f:write(header .. output .. footer)
|
||||
f:write(header .. table.concat(output) .. footer)
|
||||
f:close()
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user