Skip to content

Commit d3672d3

Browse files
gsmetgunnarmorling
authored andcommitted
HV-1480 Avoid removing and adding element to the node list
We can directly set the element in the list. It avoids some list resizing.
1 parent 27f566a commit d3672d3

File tree

1 file changed

+5
-10
lines changed
  • engine/src/main/java/org/hibernate/validator/internal/engine/path

1 file changed

+5
-10
lines changed

engine/src/main/java/org/hibernate/validator/internal/engine/path/PathImpl.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,44 +178,39 @@ private NodeImpl addMethodNode(String name, Class<?>[] parameterTypes) {
178178
public NodeImpl makeLeafNodeIterable() {
179179
currentLeafNode = NodeImpl.makeIterable( currentLeafNode );
180180

181-
nodeList.remove( nodeList.size() - 1 );
182-
nodeList.add( currentLeafNode );
181+
nodeList.set( nodeList.size() - 1, currentLeafNode );
183182
hashCode = -1;
184183
return currentLeafNode;
185184
}
186185

187186
public NodeImpl setLeafNodeIndex(Integer index) {
188187
currentLeafNode = NodeImpl.setIndex( currentLeafNode, index );
189188

190-
nodeList.remove( nodeList.size() - 1 );
191-
nodeList.add( currentLeafNode );
189+
nodeList.set( nodeList.size() - 1, currentLeafNode );
192190
hashCode = -1;
193191
return currentLeafNode;
194192
}
195193

196194
public NodeImpl setLeafNodeMapKey(Object key) {
197195
currentLeafNode = NodeImpl.setMapKey( currentLeafNode, key );
198196

199-
nodeList.remove( nodeList.size() - 1 );
200-
nodeList.add( currentLeafNode );
197+
nodeList.set( nodeList.size() - 1, currentLeafNode );
201198
hashCode = -1;
202199
return currentLeafNode;
203200
}
204201

205202
public NodeImpl setLeafNodeValue(Object value) {
206203
currentLeafNode = NodeImpl.setPropertyValue( currentLeafNode, value );
207204

208-
nodeList.remove( nodeList.size() - 1 );
209-
nodeList.add( currentLeafNode );
205+
nodeList.set( nodeList.size() - 1, currentLeafNode );
210206
hashCode = -1;
211207
return currentLeafNode;
212208
}
213209

214210
public NodeImpl setLeafNodeTypeParameter(Class<?> containerClass, Integer typeArgumentIndex) {
215211
currentLeafNode = NodeImpl.setTypeParameter( currentLeafNode, containerClass, typeArgumentIndex );
216212

217-
nodeList.remove( nodeList.size() - 1 );
218-
nodeList.add( currentLeafNode );
213+
nodeList.set( nodeList.size() - 1, currentLeafNode );
219214
hashCode = -1;
220215
return currentLeafNode;
221216
}

0 commit comments

Comments
 (0)