Allon Mureinik has uploaded a new change for review.

Change subject: core: TagsDirector: precompile backshlash removal
......................................................................

core: TagsDirector: precompile backshlash removal

Precompile the Pattern object used to remove backslashes. Since this
Pattern is never changed, in can be compiles once and save a heavy
operation each time the method is called.

Change-Id: I4a0ea8e5e6368b987d93bb087338df4e83318848
Signed-off-by: Allon Mureinik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TagsDirector.java
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/25673/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TagsDirector.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TagsDirector.java
index 49c425e..dfc5438 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TagsDirector.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TagsDirector.java
@@ -5,6 +5,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.action.TagsOperationParameters;
@@ -23,6 +24,13 @@
  * operations go throw this class
  */
 public class TagsDirector {
+
+    /**
+     * This pattern is used to replace '\\' in the expression that may be 
added by handling a '_' character with an
+     * empty string. Since we use both String and RegExp , each backslash char 
is represented by four backslash
+     * characters, so for marching two backslashes we will need eight.
+     */
+    private static final Pattern BACKSLASH_REMOVER = 
Pattern.compile("\\\\\\\\");
 
     private enum TagReturnValueIndicator {
         ID,
@@ -292,9 +300,7 @@
 
     private static void RecursiveGetTagsAndChildrenByRegExp(String 
tagNameRegExp, StringBuilder sb, Tags tag, TagReturnValueIndicator indicator) {
         if ((tag.getChildren() != null) && !tag.getChildren().isEmpty()) {
-            // The following line replaces '\\' in the expression that may be 
added by handling a '_' character with empty string.
-            // since we have here both String and RegExp , each backslash char 
is represented by four backslash chars , so for marching 2 we will need 8
-            tagNameRegExp=tagNameRegExp.replaceAll("\\\\\\\\", "");
+            tagNameRegExp = 
BACKSLASH_REMOVER.matcher(tagNameRegExp).replaceAll("");
             for (Tags child : tag.getChildren()) {
                 if (Regex.IsMatch(child.gettag_name(), tagNameRegExp)) {
                 // the tag matches the regular expression -> add it and all its


-- 
To view, visit http://gerrit.ovirt.org/25673
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a0ea8e5e6368b987d93bb087338df4e83318848
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to