Skip to content

Commit 8017177

Browse files
authored
OAK-11394 - Avoid creation of iterator when creating a CompositeEditor. (#1987)
1 parent 6f235a0 commit 8017177

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
3232
import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getAsyncLaneName;
3333
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
34-
import static org.apache.jackrabbit.oak.spi.commit.CompositeEditor.compose;
35-
import static org.apache.jackrabbit.oak.spi.commit.EditorDiff.process;
36-
import static org.apache.jackrabbit.oak.spi.commit.VisibleEditor.wrap;
3734

3835
import java.util.ArrayList;
3936
import java.util.HashMap;
@@ -57,7 +54,10 @@
5754
import org.apache.jackrabbit.oak.plugins.index.progress.TraversalRateEstimator;
5855
import org.apache.jackrabbit.oak.plugins.index.upgrade.IndexDisabler;
5956
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
57+
import org.apache.jackrabbit.oak.spi.commit.CompositeEditor;
6058
import org.apache.jackrabbit.oak.spi.commit.Editor;
59+
import org.apache.jackrabbit.oak.spi.commit.EditorDiff;
60+
import org.apache.jackrabbit.oak.spi.commit.VisibleEditor;
6161
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
6262
import org.apache.jackrabbit.oak.spi.state.NodeState;
6363
import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -134,7 +134,7 @@ public class IndexUpdate implements Editor, PathSource {
134134
/**
135135
* Editors for indexes that need to be re-indexed.
136136
*/
137-
private final Map<String, Editor> reindex = new HashMap<String, Editor>();
137+
private final Map<String, Editor> reindex = new HashMap<>();
138138

139139
public IndexUpdate(
140140
IndexEditorProvider provider, String async,
@@ -182,8 +182,10 @@ public void enter(NodeState before, NodeState after)
182182
}
183183

184184
// no-op when reindex is empty
185-
CommitFailedException exception = process(
186-
wrap(wrapProgress(compose(reindex.values()))), MISSING_NODE, after);
185+
CommitFailedException exception = EditorDiff.process(
186+
VisibleEditor.wrap(wrapProgress(CompositeEditor.compose(reindex.values()))),
187+
MISSING_NODE,
188+
after);
187189
rootState.progressReporter.reindexingTraversalEnd();
188190
if (exception != null) {
189191
throw exception;
@@ -503,7 +505,7 @@ public Editor childNodeAdded(String name, NodeState after)
503505
children.add(child);
504506
}
505507
}
506-
return compose(children);
508+
return CompositeEditor.compose(children);
507509
}
508510

509511
@Override @NotNull
@@ -518,7 +520,7 @@ public Editor childNodeChanged(
518520
children.add(child);
519521
}
520522
}
521-
return compose(children);
523+
return CompositeEditor.compose(children);
522524
}
523525

524526
@Override @Nullable
@@ -531,7 +533,7 @@ public Editor childNodeDeleted(String name, NodeState before)
531533
children.add(child);
532534
}
533535
}
534-
return compose(children);
536+
return CompositeEditor.compose(children);
535537
}
536538

537539
public void commitProgress(IndexProgress indexProgress) {

oak-store-spi/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.jackrabbit.oak.spi.commit;
1818

19-
import static java.util.Arrays.asList;
2019
import static java.util.Objects.requireNonNull;
2120

2221
import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -34,27 +33,31 @@
3433
*/
3534
public class CompositeEditor implements Editor {
3635

37-
@Nullable
3836
public static Editor compose(@NotNull Collection<? extends Editor> editors) {
37+
return compose(new ArrayList<>(editors));
38+
}
39+
40+
@Nullable
41+
public static Editor compose(@NotNull List<? extends Editor> editors) {
3942
requireNonNull(editors);
4043
switch (editors.size()) {
41-
case 0:
42-
return null;
43-
case 1:
44-
return editors.iterator().next();
45-
default:
46-
return new CompositeEditor(editors);
44+
case 0:
45+
return null;
46+
case 1:
47+
return editors.get(0);
48+
default:
49+
return new CompositeEditor(editors);
4750
}
4851
}
4952

50-
private final Collection<? extends Editor> editors;
53+
private final List<? extends Editor> editors;
5154

52-
public CompositeEditor(Collection<? extends Editor> editors) {
55+
public CompositeEditor(List<? extends Editor> editors) {
5356
this.editors = editors;
5457
}
5558

5659
public CompositeEditor(Editor... editors) {
57-
this(asList(editors));
60+
this(List.of(editors));
5861
}
5962

6063
@Override
@@ -73,7 +76,6 @@ public void leave(NodeState before, NodeState after)
7376
}
7477
}
7578

76-
7779
@Override
7880
public void propertyAdded(PropertyState after)
7981
throws CommitFailedException {
@@ -137,5 +139,4 @@ public Editor childNodeDeleted(String name, NodeState before)
137139
}
138140
return compose(list);
139141
}
140-
141142
}

0 commit comments

Comments
 (0)