From 02b7d6e5634ff24cd10bce8b01b600fcbfcb8163 Mon Sep 17 00:00:00 2001 From: djalal Date: Tue, 23 Aug 2011 09:26:06 +0000 Subject: [PATCH] o [NSE] Use a table to store the output results, and use table.concat() to concat data instead of classic concatenation. This can have a huge performance boost, check this thread: http://seclists.org/nmap-dev/2011/q3/623 --- nselib/stdnse.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index ae27aa493..7a7ed7ee8 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -479,9 +479,9 @@ local function format_output_sub(status, data, indent) -- Used to put 'ERROR: ' in front of all lines on error messages local prefix = "" -- Initialize the output string to blank (or, if we're at the top, add a newline) - local output = "" + local output = {} if(not(indent)) then - output = '\n' + insert(output, '\n') end if(not(status)) then @@ -501,12 +501,18 @@ local function format_output_sub(status, data, indent) if(data['name']) then if(data['warning'] and nmap.debugging() > 0) then - output = output .. format("%s%s%s (WARNING: %s)\n", format_get_indent(indent), prefix, data['name'], data['warning']) + insert(output, format("%s%s%s (WARNING: %s)\n", + format_get_indent(indent), prefix, + data['name'], data['warning'])) else - output = output .. format("%s%s%s\n", format_get_indent(indent), prefix, data['name']) + insert(output, format("%s%s%s\n", + format_get_indent(indent), prefix, + data['name'])) end elseif(data['warning'] and nmap.debugging() > 0) then - output = output .. format("%s%s(WARNING: %s)\n", format_get_indent(indent), prefix, data['warning']) + insert(output, format("%s%s(WARNING: %s)\n", + format_get_indent(indent), prefix, + data['warning'])) end for i, value in ipairs(data) do @@ -523,18 +529,20 @@ local function format_output_sub(status, data, indent) insert(new_indent, true) end - output = output .. format_output_sub(status, value, new_indent) + insert(output, format_output_sub(status, value, new_indent)) elseif(type(value) == 'string') then local lines = splitlines(value) for j, line in ipairs(lines) do - output = output .. format_get_indent(indent, i == #data and j == #lines) .. " " .. prefix .. line .. "\n" + insert(output, format("%s %s%s\n", + format_get_indent(indent, i == #data and j == #lines), + prefix, line)) end end end - return output + return concat(output) end ---Takes a table of output on the commandline and formats it for display to the