Skip to content

Commit

Permalink
LDEV-3210 - modernise local and argument scope pools
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jan 8, 2021
1 parent 7b9809e commit 6d57602
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
31 changes: 16 additions & 15 deletions core/src/main/java/lucee/runtime/type/scope/ScopeFactory.java
Expand Up @@ -18,29 +18,29 @@
**/
package lucee.runtime.type.scope;

import java.util.concurrent.ConcurrentLinkedQueue;

import lucee.runtime.PageContext;

/**
* creates Local and Argument scopes and recyle it
*/
public final class ScopeFactory {

private static final int MAX_SIZE = 50;

int argumentCounter = 0;
final Argument[] arguments = new Argument[] { new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(),
new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(),
new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl(), new ArgumentImpl() };

int localCounter = 0;
LocalImpl[] locals = new LocalImpl[] { new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(),
new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(), new LocalImpl(),
new LocalImpl() };
private final ConcurrentLinkedQueue<Argument> arguments = new ConcurrentLinkedQueue<Argument>();
private final ConcurrentLinkedQueue<LocalImpl> locals = new ConcurrentLinkedQueue<LocalImpl>();

/**
* @return returns an Argument scope
*/
public Argument getArgumentInstance() {
if (argumentCounter < arguments.length) {
return arguments[argumentCounter++];
Argument arg = arguments.poll();
if (arg != null) {
return arg;
}
return new ArgumentImpl();
}
Expand All @@ -49,8 +49,9 @@ public Argument getArgumentInstance() {
* @return retruns a Local Instance
*/
public LocalImpl getLocalInstance() {
if (localCounter < locals.length) {
return locals[localCounter++];
LocalImpl lcl = locals.poll();
if (lcl != null) {
return lcl;
}
return new LocalImpl();
}
Expand All @@ -59,18 +60,18 @@ public LocalImpl getLocalInstance() {
* @param argument recycle an Argument scope for reuse
*/
public void recycle(PageContext pc, Argument argument) {
if (argumentCounter <= 0 || argument.isBind()) return;
if (arguments.size() >= MAX_SIZE || argument.isBind()) return;
argument.release(pc);
arguments[--argumentCounter] = argument;
arguments.add(argument);
}

/**
* @param local recycle a Local scope for reuse
*/
public void recycle(PageContext pc, LocalImpl local) {
if (localCounter <= 0 || local.isBind()) return;
if (locals.size() >= MAX_SIZE || local.isBind()) return;
local.release(pc);
locals[--localCounter] = local;
locals.add(local);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project default="core" basedir="." name="Lucee" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

<property name="version" value="5.3.8.137-SNAPSHOT"/>
<property name="version" value="5.3.8.138-SNAPSHOT"/>

<path id="maven-ant-tasks.classpath" path="../ant/lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.3.8.137-SNAPSHOT</version>
<version>5.3.8.138-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 6d57602

Please sign in to comment.