Skip to content

Commit

Permalink
Revert "Feature/avoid hashmapint (#1773)"
Browse files Browse the repository at this point in the history
This reverts commit 4af9ce6.
  • Loading branch information
pkoenig10 committed May 22, 2021
1 parent d452b87 commit bfdf8f7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 118 deletions.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions docs/best-practices/java-coding-guidelines/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ topics:
- [Avoid Generics clutter where possible](#avoid-generics-clutter-where-possible)
- [Keep Boolean expressions simple](#keep-boolean-expressions-simple)
- [Durations: measured by longs or complex types, not by ints](#durations-measured-by-longs-or-complex-types-not-by-ints)
- [Avoid new HashMap(int), use Maps.newHashMapWithExpectedSize(int)](#avoid-new-HashMap(int))
- [APIs and Interfaces](#apis-and-interfaces)
- [Indicate failure consistently](#indicate-failure-consistently)
- [Return empty arrays and collections, not null](#return-empty-arrays-and-collections-not-null)
Expand Down Expand Up @@ -649,18 +648,6 @@ must thus be represented by `long` types, or by appropriate
non-primitive types such as Java8/Joda-Time
[Duration](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html).

### Avoid new HashMap(int)

Avoid new HashMap(int), use Maps#newHashMapWithExpectedSize(int) instead.

The behavior of `new HashMap(int)` is misleading -- the parameter represents an
internal size rather than an ability to hold that number of elements. If a HashMap
with capacity K receives K elements, it will increase its capacity to 2*K along the way.
This is because HashMap doubles its internal storage by 2 once it reaches 75% capacity.

The Guava static method `Maps.newHashMapWithExpectedSize(int)` creates a HashMap which
will not resize if provided the given number of elements.

## APIs and Interfaces

### Indicate failure consistently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class BaselineErrorProneExtension {
*/
private static final ImmutableList<String> DEFAULT_PATCH_CHECKS = ImmutableList.of(
// Baseline checks
"AvoidNewHashMapInt",
"CatchBlockLogException",
// TODO(ckozak): re-enable pending scala check
// "CatchSpecificity",
Expand Down

0 comments on commit bfdf8f7

Please sign in to comment.