Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Simplify code. Use putIfAbsent instead of custom check.

[#636][closes #641]
  • Loading branch information
mp911de committed Mar 4, 2024
1 parent b6cac40 commit 057f3f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/main/java/io/r2dbc/postgresql/PostgresqlRow.java
Expand Up @@ -59,9 +59,7 @@ final class PostgresqlRow implements io.r2dbc.postgresql.api.PostgresqlRow {
this.data = Assert.requireNonNull(data, "data must not be null");

if (metadata instanceof PostgresqlRowMetadata) {
this.columnNameIndexCacheMap = Assert.requireNonNull(
((PostgresqlRowMetadata) metadata).getColumnNameIndexMap(),
"columnNameIndexCacheMap must not be null");
this.columnNameIndexCacheMap = ((PostgresqlRowMetadata) metadata).getColumnNameIndexMap();
} else {
this.columnNameIndexCacheMap = createColumnNameIndexMap(this.fields);
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/io/r2dbc/postgresql/PostgresqlRowMetadata.java
Expand Up @@ -48,15 +48,13 @@ final class PostgresqlRowMetadata extends AbstractCollection<String> implements

PostgresqlRowMetadata(List<PostgresqlColumnMetadata> columnMetadatas) {
this.columnMetadatas = Assert.requireNonNull(columnMetadatas, "columnMetadatas must not be null");
this.nameKeyedColumns = new LinkedHashMap<>();
this.nameKeyedColumns = new LinkedHashMap<>(columnMetadatas.size(), 1);
this.columnNameIndexMap = new HashMap<>(columnMetadatas.size(), 1);

int i = 0;
for (PostgresqlColumnMetadata columnMetadata : columnMetadatas) {
if (!this.nameKeyedColumns.containsKey(columnMetadata.getName())) {
this.nameKeyedColumns.put(columnMetadata.getName(), columnMetadata);
}
columnNameIndexMap.putIfAbsent(columnMetadata.getName().toLowerCase(Locale.ROOT), i++);
this.nameKeyedColumns.putIfAbsent(columnMetadata.getName(), columnMetadata);
this.columnNameIndexMap.putIfAbsent(columnMetadata.getName().toLowerCase(Locale.ROOT), i++);
}
}

Expand Down

0 comments on commit 057f3f1

Please sign in to comment.