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 9359974 commit eb559fe
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 eb559fe

Please sign in to comment.