Skip to content

Commit f39e179

Browse files
gsmetgunnarmorling
authored andcommitted
HV-1480 Setting the key or the index already makes the node iterable
So we don't need to do it twice. Note that this change uncovers the fact that in ConstraintValidatorContext, calling atKey() or atIndex() makes the node iterable. It was already the case before and I think it's acceptable. It brings its own performance improvements as it avoids initializing 1 NodeImpl and creating 1 copy of the Path.
1 parent 7c00b44 commit f39e179

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

engine/src/main/java/org/hibernate/validator/internal/engine/ValidatorImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,13 @@ public void iterableValue(String nodeName, Object value) {
670670

671671
@Override
672672
public void indexedValue(String nodeName, int index, Object value) {
673-
valueContext.markCurrentPropertyAsIterable();
674-
valueContext.setIndex( index );
673+
valueContext.markCurrentPropertyAsIterableAndSetIndex( index );
675674
doValidate( value, nodeName );
676675
}
677676

678677
@Override
679678
public void keyedValue(String nodeName, Object key, Object value) {
680-
valueContext.markCurrentPropertyAsIterable();
681-
valueContext.setKey( key );
679+
valueContext.markCurrentPropertyAsIterableAndSetKey( key );
682680
doValidate( value, nodeName );
683681
}
684682

engine/src/main/java/org/hibernate/validator/internal/engine/ValueContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public final void markCurrentPropertyAsIterable() {
159159
propertyPath.makeLeafNodeIterable();
160160
}
161161

162-
public final void setKey(Object key) {
163-
propertyPath.setLeafNodeMapKey( key );
162+
public final void markCurrentPropertyAsIterableAndSetKey(Object key) {
163+
propertyPath.makeLeafNodeIterableAndSetMapKey( key );
164164
}
165165

166-
public final void setIndex(Integer index) {
167-
propertyPath.setLeafNodeIndex( index );
166+
public final void markCurrentPropertyAsIterableAndSetIndex(Integer index) {
167+
propertyPath.makeLeafNodeIterableAndSetIndex( index );
168168
}
169169

170170
/**

engine/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintValidatorContextImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ public DeferredNodeBuilder inContainer(Class<?> containerClass, Integer typeArgu
320320

321321
@Override
322322
public NodeBuilder atKey(Object key) {
323-
propertyPath.setLeafNodeMapKey( key );
323+
propertyPath.makeLeafNodeIterableAndSetMapKey( key );
324324
addLeafNode();
325325
return new NodeBuilder( messageTemplate, propertyPath );
326326
}
327327

328328
@Override
329329
public NodeBuilder atIndex(Integer index) {
330-
propertyPath.setLeafNodeIndex( index );
330+
propertyPath.makeLeafNodeIterableAndSetIndex( index );
331331
addLeafNode();
332332
return new NodeBuilder( messageTemplate, propertyPath );
333333
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static NodeImpl makeIterable(NodeImpl node) {
207207
);
208208
}
209209

210-
public static NodeImpl setIndex(NodeImpl node, Integer index) {
210+
public static NodeImpl makeIterableAndSetIndex(NodeImpl node, Integer index) {
211211
return new NodeImpl(
212212
node.name,
213213
node.parent,
@@ -223,7 +223,7 @@ public static NodeImpl setIndex(NodeImpl node, Integer index) {
223223
);
224224
}
225225

226-
public static NodeImpl setMapKey(NodeImpl node, Object key) {
226+
public static NodeImpl makeIterableAndSetMapKey(NodeImpl node, Object key) {
227227
return new NodeImpl(
228228
node.name,
229229
node.parent,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,20 @@ public NodeImpl makeLeafNodeIterable() {
202202
return currentLeafNode;
203203
}
204204

205-
public NodeImpl setLeafNodeIndex(Integer index) {
205+
public NodeImpl makeLeafNodeIterableAndSetIndex(Integer index) {
206206
requiresWriteableNodeList();
207207

208-
currentLeafNode = NodeImpl.setIndex( currentLeafNode, index );
208+
currentLeafNode = NodeImpl.makeIterableAndSetIndex( currentLeafNode, index );
209209

210210
nodeList.set( nodeList.size() - 1, currentLeafNode );
211211
hashCode = -1;
212212
return currentLeafNode;
213213
}
214214

215-
public NodeImpl setLeafNodeMapKey(Object key) {
215+
public NodeImpl makeLeafNodeIterableAndSetMapKey(Object key) {
216216
requiresWriteableNodeList();
217217

218-
currentLeafNode = NodeImpl.setMapKey( currentLeafNode, key );
218+
currentLeafNode = NodeImpl.makeIterableAndSetMapKey( currentLeafNode, key );
219219

220220
nodeList.set( nodeList.size() - 1, currentLeafNode );
221221
hashCode = -1;
@@ -394,10 +394,10 @@ private static PathImpl parseProperty(String propertyName) {
394394
if ( indexOrKey != null && indexOrKey.length() > 0 ) {
395395
try {
396396
Integer i = Integer.parseInt( indexOrKey );
397-
path.setLeafNodeIndex( i );
397+
path.makeLeafNodeIterableAndSetIndex( i );
398398
}
399399
catch (NumberFormatException e) {
400-
path.setLeafNodeMapKey( indexOrKey );
400+
path.makeLeafNodeIterableAndSetMapKey( indexOrKey );
401401
}
402402
}
403403

engine/src/main/java/org/hibernate/validator/internal/metadata/core/MetaConstraint.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,13 @@ public void iterableValue(String nodeName, Object value) {
194194

195195
@Override
196196
public void indexedValue(String nodeName, int index, Object value) {
197-
valueContext.markCurrentPropertyAsIterable();
198-
valueContext.setIndex( index );
197+
valueContext.markCurrentPropertyAsIterableAndSetIndex( index );
199198
doValidate( value, nodeName );
200199
}
201200

202201
@Override
203202
public void keyedValue(String nodeName, Object key, Object value) {
204-
valueContext.markCurrentPropertyAsIterable();
205-
valueContext.setKey( key );
203+
valueContext.markCurrentPropertyAsIterableAndSetKey( key );
206204
doValidate( value, nodeName );
207205
}
208206

0 commit comments

Comments
 (0)