From 1499ea9e75d744b35b6a984dbbb6de5e20e642d5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 20 May 2016 15:32:07 +0200 Subject: [PATCH] BUG-5410: add minimal IntStack implementation Using Stack forces integer boxing, which costing us performance. This patch adds a specialized primitive-based stack, which provides the minimal needed implementation. Change-Id: Iee0e977ab87ce32871ddb468dbda47c4afa4e086 Signed-off-by: Robert Varga --- .../yangtools/xsd/regex/IntStack.java | 56 +++++++++++++++++++ .../xsd/regex/RegularExpression.java | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/IntStack.java diff --git a/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/IntStack.java b/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/IntStack.java new file mode 100644 index 0000000000..ca9a970ea9 --- /dev/null +++ b/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/IntStack.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.opendaylight.yangtools.xsd.regex; + +import java.util.Arrays; +import java.util.EmptyStackException; +import javax.annotation.concurrent.NotThreadSafe; + +/** + * A specialized minimal implementation of Stack, which operations on simple ints. + */ +@NotThreadSafe +final class IntStack { + private static final int DEFAULT_SIZE = 10; + private static final int INCREMENT = 10; + private int[] items; + private int count = 0; + + IntStack() { + this(DEFAULT_SIZE); + } + + IntStack(final int size) { + items = new int[size]; + } + + void push(final int item) { + if (count == items.length) { + items = Arrays.copyOf(items, items.length + INCREMENT); + } + + items[count++] = item; + } + + int pop() { + if (count == 0) { + throw new EmptyStackException(); + } + + return items[--count]; + } +} diff --git a/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/RegularExpression.java b/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/RegularExpression.java index 0e5533d919..17bc1d6be1 100644 --- a/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/RegularExpression.java +++ b/third-party/xsd-regex/src/main/java/org/opendaylight/yangtools/xsd/regex/RegularExpression.java @@ -1050,7 +1050,7 @@ public class RegularExpression implements java.io.Serializable { private int match(Context con, Op op, int offset, int dx, int opts) { final ExpressionTarget target = con.target; final Stack opStack = new Stack<>(); - final Stack dataStack = new Stack<>(); + final IntStack dataStack = new IntStack(); final boolean isSetIgnoreCase = isSet(opts, IGNORE_CASE); int retValue = -1; boolean returned = false; -- 2.36.6