From f51de3bc0ea456d073d2588a4b2534ca98c79346 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 3 Jun 2014 17:22:20 +0000 Subject: [PATCH] Make NmapOutputViewer.go_to_host more efficient Instead of loading the entire output into a new string with gtk.TextBuffer.get_text, we use the gtk.TextIter.forward_search method. This works because we don't need to use regular expressions to find a static string. --- zenmap/zenmapGUI/NmapOutputViewer.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/zenmap/zenmapGUI/NmapOutputViewer.py b/zenmap/zenmapGUI/NmapOutputViewer.py index 40fa0b184..d1bf8b7d5 100644 --- a/zenmap/zenmapGUI/NmapOutputViewer.py +++ b/zenmap/zenmapGUI/NmapOutputViewer.py @@ -216,16 +216,14 @@ class NmapOutputViewer (gtk.VBox): def go_to_host(self, host): """Go to host line on nmap output result""" buff = self.text_view.get_buffer() - start_iter, end_iter = buff.get_bounds() + start_iter = buff.get_start_iter() - output = buff.get_text(start_iter, end_iter).split("\n") - re_host = re.compile(r'^Nmap scan report for %s\s*$' % re.escape(host)) - - for i in xrange(len(output)): - if re_host.match(output[i]): - self.text_view.scroll_to_iter( - buff.get_iter_at_line(i), 0, True, 0, 0) - break + found = start_iter.forward_search( + "\nNmap scan report for %s\n" % host, gtk.TEXT_SEARCH_TEXT_ONLY + )[0] + if not found.forward_line(): + return + self.text_view.scroll_to_iter(found, 0, True, 0, 0) def show_output_properties(self, widget): nmap_out_prop = NmapOutputProperties(self.text_view)