Skip to content

Commit 03ac4a7

Browse files
committed
Clone IVariables in IVariableList clone
Allows for not recreating a new `IVariable` for every assign operation.
1 parent bef7968 commit 03ac4a7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/laytonsmith/core/constructs/IVariable.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public IVariable clone() throws CloneNotSupportedException {
9696
return clone;
9797
}
9898

99+
/**
100+
* Create a clone of this {@link IVariable} using the same variable value reference.
101+
* @return The clone.
102+
*/
103+
public IVariable shallowClone() {
104+
return new IVariable(type, name, varValue, definedTarget);
105+
}
106+
99107
@Override
100108
public boolean isDynamic() {
101109
return true;

src/main/java/com/laytonsmith/core/constructs/IVariableList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ public String toString() {
137137
@Override
138138
public IVariableList clone() {
139139
IVariableList clone = new IVariableList(this);
140-
clone.varList = new HashMap<>(varList);
140+
for(IVariable var : varList.values()) {
141+
clone.set(var.shallowClone());
142+
}
141143
return clone;
142144
}
143145

0 commit comments

Comments
 (0)