Skip to content

Commit 5d3168e

Browse files
committed
Avoid redundant processing and isReference checks on * usage
1 parent 17f12cc commit 5d3168e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

metafix/src/main/java/org/metafacture/metafix/FixPath.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,25 @@ private void removeNestedFrom(final Value value) {
263263
/*package-private*/ private Value insertInto(final Array array, final InsertMode mode, final Value newValue) {
264264
// basic idea: reuse findIn logic here? setIn(findIn(array), newValue)
265265
final String field = path[0];
266-
if (path.length == 1) {
267-
if (field.equals(ASTERISK)) {
266+
if (field.equals(ASTERISK)) {
267+
if (path.length == 1) {
268268
for (int i = 0; i < array.size(); ++i) {
269269
mode.apply(array, String.valueOf(i + 1), newValue);
270270
}
271271
}
272272
else {
273-
mode.apply(array, field, newValue);
273+
array.add(Value.newHash(h -> new FixPath(tail(path)).insertInto(h, mode, newValue)));
274274
}
275275
}
276276
else {
277-
final String[] tail = tail(path);
278-
if (isReference(field)) {
279-
return processRef(getReferencedValue(array, field), mode, newValue, field, tail);
277+
if (path.length == 1) {
278+
mode.apply(array, field, newValue);
279+
}
280+
else {
281+
if (isReference(field)) {
282+
return processRef(getReferencedValue(array, field), mode, newValue, field, tail(path));
283+
}
280284
}
281-
array.add(Value.newHash(h -> new FixPath(path).insertInto(h, mode, newValue)));
282285
}
283286
return new Value(array);
284287
}
@@ -287,12 +290,7 @@ private void removeNestedFrom(final Value value) {
287290
// basic idea: reuse findIn logic here? setIn(findIn(hash), newValue)
288291
final String field = path[0];
289292
if (path.length == 1) {
290-
if (field.equals(ASTERISK)) {
291-
hash.forEach((k, v) -> mode.apply(hash, k, newValue)); //TODO: WDCD? insert into each element?
292-
}
293-
else {
294-
mode.apply(hash, field, newValue);
295-
}
293+
mode.apply(hash, field, newValue);
296294
}
297295
else {
298296
final String[] tail = tail(path);

0 commit comments

Comments
 (0)