From 6e969dacd93f9653b374c4e589604bb0291d8dbe Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Fri, 28 Aug 2015 17:21:19 +0200 Subject: [PATCH] Make regexes in LaurisItem static and readonly. In order to speed parsing up a little bit. --- .../Importer/ZaaImporter/LaurisItem.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs index 7d76f9e..2996795 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs @@ -103,19 +103,15 @@ namespace zaaReloaded2.Importer.ZaaImporter // "HBs-Antigen: neg. ;" // "Erythrozyten (U): + [negativ]" Match match; - Regex numericalRegex = new Regex( - @"(?[^:]+):\s*(?[\d,.]+)\s*(?\[[^\]]+])?\s*(?[^;]+)?"); - Regex categoricalRegex = new Regex( - @"(?[^:]+):\s*(?[^[;]+)\s*(\[(?[^\]]+)])?"); - if (numericalRegex.IsMatch(LaurisText)) + if (_numericalRegex.IsMatch(LaurisText)) { - match = numericalRegex.Match(LaurisText); + match = _numericalRegex.Match(LaurisText); ParseLimits(match); Value = match.Groups["value"].Value.Trim().Replace(',', '.'); } else { - match = categoricalRegex.Match(LaurisText); + match = _categoricalRegex.Match(LaurisText); Normal = match.Groups["normal"].Value.Trim(); Value = match.Groups["value"].Value.Trim(); } @@ -136,8 +132,7 @@ namespace zaaReloaded2.Importer.ZaaImporter { if (match.Groups["limits"].Success) { - Regex limitRegex = new Regex(@"\[(?[-\d,.]+)?\s*(?\S+)\s*(?[-\d,.]+)?]"); - Match limitMatch = limitRegex.Match(match.Groups["limits"].Value); + Match limitMatch = _limitRegex.Match(match.Groups["limits"].Value); if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success) { // Use InvariantCulture because Lauris always outputs dots as decimal separator @@ -203,6 +198,11 @@ namespace zaaReloaded2.Importer.ZaaImporter #region Fields + static readonly Regex _numericalRegex = new Regex( + @"(?[^:]+):\s*(?[\d,.]+)\s*(?\[[^\]]+])?\s*(?[^;]+)?"); + static readonly Regex _categoricalRegex = new Regex( + @"(?[^:]+):\s*(?[^[;]+)\s*(\[(?[^\]]+)])?"); + static readonly Regex _limitRegex = new Regex(@"\[(?[-\d,.]+)?\s*(?\S+)\s*(?[-\d,.]+)?]"); static readonly Regex _materialRegex = new Regex(@"\((?(SU|PU))\)"); #endregion