Skip to content

Commit ea35ae4

Browse files
committed
Polishing.
Fix benchmarks after polishing. [#444][#409] Signed-off-by: Mark Paluch <[email protected]>
1 parent bdd9e0d commit ea35ae4

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/jmh/java/io/r2dbc/postgresql/CodecRegistryBenchmarks.java renamed to src/jmh/java/io/r2dbc/postgresql/codec/CodecRegistryBenchmarks.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.r2dbc.postgresql;
17+
package io.r2dbc.postgresql.codec;
1818

1919
import io.netty.buffer.ByteBufAllocator;
2020
import io.netty.buffer.UnpooledByteBufAllocator;
21-
import io.r2dbc.postgresql.codec.CodecFinderCacheImpl;
22-
import io.r2dbc.postgresql.codec.CodecFinderDefaultImpl;
23-
import io.r2dbc.postgresql.codec.Codecs;
24-
import io.r2dbc.postgresql.codec.DefaultCodecs;
21+
import io.r2dbc.postgresql.BenchmarkSettings;
2522
import io.r2dbc.postgresql.util.ByteBufUtils;
2623
import org.junit.platform.commons.annotation.Testable;
2724
import org.openjdk.jmh.annotations.Benchmark;
@@ -65,9 +62,9 @@ public static class CodecRegistryHolder {
6562

6663
final ByteBufAllocator byteBufAllocator = new UnpooledByteBufAllocator(false, true);
6764

68-
DefaultCodecs cacheEnabledRegistry = new DefaultCodecs(byteBufAllocator, false, new CodecFinderCacheImpl());
65+
DefaultCodecs cacheEnabledRegistry = new DefaultCodecs(this.byteBufAllocator, false, CachedCodecLookup::new);
6966

70-
DefaultCodecs cacheDisabledRegistry = new DefaultCodecs(byteBufAllocator, false, new CodecFinderDefaultImpl());
67+
DefaultCodecs cacheDisabledRegistry = new DefaultCodecs(this.byteBufAllocator, false, DefaultCodecLookup::new);
7168

7269
}
7370

@@ -135,4 +132,4 @@ public void encodeWithCacheDisabledRegistry(CodecRegistryHolder holder, Blackhol
135132
encode(holder.cacheDisabledRegistry, holder.iterations, voodoo);
136133
}
137134

138-
}
135+
}

src/main/java/io/r2dbc/postgresql/codec/DefaultCodecs.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Iterator;
3333
import java.util.List;
3434
import java.util.concurrent.CopyOnWriteArrayList;
35+
import java.util.function.Function;
3536

3637
import static io.r2dbc.postgresql.client.EncodedParameter.NULL_VALUE;
3738

@@ -74,13 +75,13 @@ public DefaultCodecs(ByteBufAllocator byteBufAllocator, boolean preferAttachedBu
7475
*
7576
* @param byteBufAllocator the {@link ByteBufAllocator} to use for encoding
7677
* @param preferAttachedBuffers whether to prefer attached (pooled) {@link ByteBuf buffers}. Use {@code false} (default) to use detached buffers which minimize the risk of memory leaks.
77-
* @param codecLookup the {@link CodecLookup} to use for finding relevant codecs
78+
* @param codecLookupFunction provides the {@link CodecLookup} to use for finding relevant codecs
7879
*/
79-
DefaultCodecs(ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers, CodecLookup codecLookup) {
80+
DefaultCodecs(ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers, Function<CodecRegistry, CodecLookup> codecLookupFunction) {
8081
Assert.requireNonNull(byteBufAllocator, "byteBufAllocator must not be null");
81-
Assert.requireNonNull(codecLookup, "codecFinder must not be null");
82+
Assert.requireNonNull(codecLookupFunction, "codecLookupFunction must not be null");
8283

83-
this.codecLookup = codecLookup;
84+
this.codecLookup = codecLookupFunction.apply(this);
8485
this.codecs = getDefaultCodecs(byteBufAllocator, preferAttachedBuffers);
8586
this.codecLookup.afterCodecAdded();
8687
}

0 commit comments

Comments
 (0)