Skip to content

Commit 9419d48

Browse files
authored
Remove RowAccumulator related code (#1400)
The alternative to ArrayList has never been used in Vert.x 4. We can get rid of it in Vert.x 5. Signed-off-by: Thomas Segismont <[email protected]>
1 parent faf25a7 commit 9419d48

File tree

10 files changed

+21
-563
lines changed

10 files changed

+21
-563
lines changed

vertx-sql-client/pom.xml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -62,58 +62,6 @@
6262
<type>test-jar</type>
6363
<scope>test</scope>
6464
</dependency>
65-
<dependency>
66-
<groupId>org.openjdk.jmh</groupId>
67-
<artifactId>jmh-core</artifactId>
68-
<version>${jmh.version}</version>
69-
<scope>test</scope>
70-
</dependency>
71-
<dependency>
72-
<groupId>org.openjdk.jmh</groupId>
73-
<artifactId>jmh-generator-annprocess</artifactId>
74-
<version>${jmh.version}</version>
75-
<scope>test</scope>
76-
</dependency>
7765
</dependencies>
7866

79-
<profiles>
80-
<profile>
81-
<id>benchmarks</id>
82-
<build>
83-
<plugins>
84-
<plugin>
85-
<artifactId>maven-assembly-plugin</artifactId>
86-
<executions>
87-
<execution>
88-
<id>assemble-benchmarks</id>
89-
<phase>package</phase>
90-
<goals>
91-
<goal>single</goal>
92-
</goals>
93-
<configuration>
94-
<archive>
95-
<manifest>
96-
<mainClass>org.openjdk.jmh.Main</mainClass>
97-
</manifest>
98-
</archive>
99-
<descriptors>
100-
<descriptor>src/test/assembly/benchmarks.xml</descriptor>
101-
</descriptors>
102-
</configuration>
103-
</execution>
104-
</executions>
105-
</plugin>
106-
</plugins>
107-
</build>
108-
<dependencies>
109-
<dependency>
110-
<groupId>org.openjdk.jmh</groupId>
111-
<artifactId>jmh-generator-annprocess</artifactId>
112-
<version>${jmh.version}</version>
113-
<scope>test</scope>
114-
</dependency>
115-
</dependencies>
116-
</profile>
117-
</profiles>
118-
11967
</project>

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowSetImpl.java

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import io.vertx.sqlclient.Row;
2020
import io.vertx.sqlclient.RowIterator;
2121
import io.vertx.sqlclient.RowSet;
22-
import io.vertx.sqlclient.impl.accumulator.ArrayListRowAccumulator;
23-
import io.vertx.sqlclient.impl.accumulator.RowAccumulator;
2422

25-
import java.util.NoSuchElementException;
23+
import java.util.ArrayList;
24+
import java.util.Collections;
25+
import java.util.Iterator;
26+
import java.util.List;
2627
import java.util.function.Function;
2728
import java.util.stream.Collector;
2829

@@ -38,9 +39,7 @@ class RowSetImpl<R> extends SqlResultBase<RowSet<R>> implements RowSet<R> {
3839
static <U> Collector<Row, RowSetImpl<U>, RowSet<U>> collector(Function<Row, U> mapper) {
3940
return Collector.of(
4041
RowSetImpl::new,
41-
(set, row) -> {
42-
set.add(mapper.apply(row));
43-
},
42+
(set, row) -> set.add(mapper.apply(row)),
4443
(set1, set2) -> null, // Shall not be invoked as this is sequential
4544
(set) -> set
4645
);
@@ -52,65 +51,38 @@ static <U> Function<RowSet<U>, RowSetImpl<U>> factory() {
5251
return rs -> (RowSetImpl<U>) rs;
5352
}
5453

55-
private R firstRow;
56-
private RowAccumulator<R> rowAccumulator;
54+
private List<R> rowAccumulator = Collections.emptyList();
5755

5856
@Override
5957
public RowSet<R> value() {
6058
return this;
6159
}
6260

6361
private void add(R row) {
64-
if (rowAccumulator != null) {
65-
rowAccumulator.accept(row);
66-
} else if (firstRow != null) {
67-
rowAccumulator = new ArrayListRowAccumulator<>();
68-
rowAccumulator.accept(firstRow);
69-
rowAccumulator.accept(row);
70-
firstRow = null;
71-
} else {
72-
firstRow = row;
62+
if (rowAccumulator.isEmpty()) {
63+
rowAccumulator = new ArrayList<>();
7364
}
65+
rowAccumulator.add(row);
7466
}
7567

7668
@Override
7769
public RowIterator<R> iterator() {
78-
return rowAccumulator != null ? rowAccumulator.iterator() : SingletonRowIterator.createFor(firstRow);
70+
Iterator<R> iter = rowAccumulator.iterator();
71+
return new RowIterator<R>() {
72+
@Override
73+
public boolean hasNext() {
74+
return iter.hasNext();
75+
}
76+
77+
@Override
78+
public R next() {
79+
return iter.next();
80+
}
81+
};
7982
}
8083

8184
@Override
8285
public RowSetImpl<R> next() {
8386
return (RowSetImpl<R>) super.next();
8487
}
85-
86-
private static final class SingletonRowIterator<ROW> implements RowIterator<ROW> {
87-
88-
static final SingletonRowIterator<Object> EMPTY_INSTANCE = new SingletonRowIterator<>(null);
89-
90-
ROW row;
91-
92-
SingletonRowIterator(ROW row) {
93-
this.row = row;
94-
}
95-
96-
@SuppressWarnings("unchecked")
97-
static <X> SingletonRowIterator<X> createFor(X row) {
98-
return row != null ? new SingletonRowIterator<>(row) : (SingletonRowIterator<X>) EMPTY_INSTANCE;
99-
}
100-
101-
@Override
102-
public boolean hasNext() {
103-
return row != null;
104-
}
105-
106-
@Override
107-
public ROW next() {
108-
if (row != null) {
109-
ROW res = row;
110-
row = null;
111-
return res;
112-
}
113-
throw new NoSuchElementException();
114-
}
115-
}
11688
}

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/accumulator/ArrayListRowAccumulator.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/accumulator/ChunkedRowAccumulator.java

Lines changed: 0 additions & 116 deletions
This file was deleted.

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/accumulator/RowAccumulator.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)