WICKET-3335 Add impl of ComponentQueue based on HashMap MiniMap is not hash based so it won't gain CPU performance over ComponentQueue
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e95c7129 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e95c7129 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e95c7129 Branch: refs/heads/master Commit: e95c7129950ed1fb53341ddf0da41e20ad185adb Parents: a51ed31 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Fri Feb 14 17:04:08 2014 +0200 Committer: Igor Vaynberg <[email protected]> Committed: Thu Feb 20 23:37:15 2014 -0800 ---------------------------------------------------------------------- .../java/org/apache/wicket/ComponentQueue2.java | 102 +++++++++++++++++++ .../java/org/apache/wicket/MarkupContainer.java | 9 +- .../ComponentQueueingPerformanceTest.java | 5 +- 3 files changed, 108 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/e95c7129/wicket-core/src/main/java/org/apache/wicket/ComponentQueue2.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ComponentQueue2.java b/wicket-core/src/main/java/org/apache/wicket/ComponentQueue2.java new file mode 100644 index 0000000..ec5251c --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/ComponentQueue2.java @@ -0,0 +1,102 @@ +/* + * 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.apache.wicket; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.wicket.util.lang.Args; + +/** + * Manages the component queue. + * + * @author igor + */ +class ComponentQueue2 +{ + private static final int INITIAL = 8; + + private Map<String, Component> queue; + private int queueSize = 0; + + void add(Component... components) + { + for (Component component : components) + { + add(component); + } + } + + void add(Component component) + { + Args.notNull(component, "component"); + + if (queue == null) + { + queue = new HashMap<>(INITIAL, 1); + } + + Component old = queue.put(component.getId(), component); + if (old != null) + { + throw new WicketRuntimeException("A component with id: " + component.getId() + + " has already been queued"); + } + queueSize++; + } + + Component remove(String id) + { + if (queue != null) + { + Component removed = queue.remove(id); + if (removed != null) + { + queueSize--; + if (isEmpty()) + { + queue = null; + } + return removed; + } + } + return null; + } + + public boolean isEmpty() + { + return queueSize == 0; + } + + public Component get(String id) + { + if (queue != null) + { + return queue.get(id); + } + return null; + } + + @Override + public String toString() + { + return "ComponentQueue{" + + "queueSize=" + queueSize + + ", queue=" + queue + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/e95c7129/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java index c62433d..5005f29 100644 --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java @@ -2054,11 +2054,6 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp return this; } - ComponentQueue getQueue() - { - return queue; - } - void dequeue() { if (!(this instanceof IQueueRegion)) @@ -2183,8 +2178,8 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp for (int j = containers.size() - 1; j >= 0; j--) { MarkupContainer container = containers.get(j); - child = container.getQueue() != null - ? container.getQueue().remove(id) + child = container.queue != null + ? container.queue.remove(id) : null; if (child != null) { http://git-wip-us.apache.org/repos/asf/wicket/blob/e95c7129/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingPerformanceTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingPerformanceTest.java b/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingPerformanceTest.java index d3800b8..a3ee3d6 100644 --- a/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingPerformanceTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingPerformanceTest.java @@ -35,11 +35,14 @@ import org.apache.wicket.mock.MockApplication; import org.apache.wicket.model.IModel; import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.util.SlowTests; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.WicketTester; import org.junit.Test; +import org.junit.experimental.categories.Category; +@Category(SlowTests.class) public class ComponentQueueingPerformanceTest extends WicketTestCase { private void run(Class<? extends Page> pageClass) @@ -49,7 +52,7 @@ public class ComponentQueueingPerformanceTest extends WicketTestCase tester.destroy(); } - // @Test + @Test public void performance() { final int warmup = 30;
