Skip to content

Commit 8c1111b

Browse files
NicoPieltonygermano
authored andcommitted
Cache compiled regex Pattern in MirthTree
Pattern.compile(" (\\(.*\\))") was called on every iteration of two tree-traversal while-loops in constructVariableName and constructNodeDescription. Pattern compilation is expensive and the pattern never changes. Extracted to a static final field. Signed-off-by: Nico Piel <nico.piel@hotmail.de>
1 parent 2e0ff41 commit 8c1111b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

client/src/com/mirth/connect/client/ui/components/MirthTree.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
public class MirthTree extends JXTree implements DropTargetListener {
4848

49+
private static final Pattern PARENT_PATTERN = Pattern.compile(" (\\(.*\\))");
50+
4951
private Frame parent;
5052
private MyFilter mf;
5153
private FilterTreeModel ftm;
@@ -502,8 +504,7 @@ public static String constructVariable(TreeNode parent) {
502504
// because we don't want to include the root node.
503505
while (node != null && node.getParent() != null) {
504506
String parentName = node.getValue();
505-
Pattern pattern = Pattern.compile(" (\\(.*\\))");
506-
Matcher matcher = pattern.matcher(parentName.toString());
507+
Matcher matcher = PARENT_PATTERN.matcher(parentName.toString());
507508

508509
if (serializationType.equals(SerializationType.JSON) && node.isArrayElement()) {
509510
if (variable.length() != 0) {
@@ -566,8 +567,7 @@ public static String constructNodeDescription(TreeNode parent) {
566567
// because we don't want to include the root node.
567568
while (node != null && node.getParent() != null) {
568569
String parentName = node.getValue();
569-
Pattern pattern = Pattern.compile(" (\\(.*\\))");
570-
Matcher matcher = pattern.matcher(parentName.toString());
570+
Matcher matcher = PARENT_PATTERN.matcher(parentName.toString());
571571

572572
// Get the index of the parent about to be added.
573573
String parentIndex = "";

0 commit comments

Comments
 (0)