diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2016-11-01 10:29:45 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2016-11-01 12:08:40 +0100 |
commit | e65e41140c2ff685c4a9a943282ca20fd8c06d0d (patch) | |
tree | 75a60ff5662883153db1d53a9209bae36d129517 | |
parent | b552f3880f07ff4801ab365b687a91bcfb15d038 (diff) | |
download | vala-e65e41140c2ff685c4a9a943282ca20fd8c06d0d.tar.gz |
Don't create constant Regex on demand and use static field where possible
-rw-r--r-- | ccode/valaccodewriter.vala | 7 | ||||
-rw-r--r-- | vala/valacodewriter.vala | 6 | ||||
-rw-r--r-- | vala/valareport.vala | 5 |
3 files changed, 12 insertions, 6 deletions
diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index b6a32384e..281ff6e43 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -48,6 +48,8 @@ public class Vala.CCodeWriter { get { return _bol; } } + static GLib.Regex fix_indent_regex; + private string temp_filename; private bool file_exists; @@ -220,7 +222,8 @@ public class Vala.CCodeWriter { bool first = true; // discard tabs at beginning of line - var regex = new GLib.Regex ("^\t+"); + if (fix_indent_regex == null) + fix_indent_regex = new GLib.Regex ("^\t+");; foreach (unowned string line in text.split ("\n")) { if (!first) { @@ -229,7 +232,7 @@ public class Vala.CCodeWriter { first = false; } - var lineparts = regex.replace_literal (line, -1, 0, "").split ("*/"); + var lineparts = fix_indent_regex.replace_literal (line, -1, 0, "").split ("*/"); for (int i = 0; lineparts[i] != null; i++) { stream.puts (lineparts[i]); diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 99a9725ae..8c0e68804 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -28,6 +28,8 @@ * Code visitor generating Vala API file for the public interface. */ public class Vala.CodeWriter : CodeVisitor { + static GLib.Regex fix_indent_regex; + private CodeContext context; FileStream stream; @@ -1502,9 +1504,9 @@ public class Vala.CodeWriter : CodeVisitor { } private void write_comment (Comment comment) { - Regex fix_indent_regex; try { - fix_indent_regex = new Regex ("\\n[\\t ]*"); + if (fix_indent_regex == null) + fix_indent_regex = new Regex ("\\n[\\t ]*"); } catch (Error e) { assert_not_reached (); } diff --git a/vala/valareport.vala b/vala/valareport.vala index 67b3a80b6..f977dce03 100644 --- a/vala/valareport.vala +++ b/vala/valareport.vala @@ -100,6 +100,7 @@ public class Vala.Report : Object { public bool enable_warnings { get; set; default = true; } + static GLib.Regex val_regex; /** * Set all colors by string @@ -109,9 +110,9 @@ public class Vala.Report : Object { * }}} */ public bool set_colors (string str) { - Regex val_regex; try { - val_regex = new Regex ("^\\s*[0-9]+(;[0-9]*)*\\s*$"); + if (val_regex == null) + val_regex = new Regex ("^\\s*[0-9]+(;[0-9]*)*\\s*$"); } catch (RegexError e) { assert_not_reached (); } |