Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AttributesBuilder toBuilder() {
return new ArrayBackedAttributesBuilder(new ArrayList<>(data()));
}

@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") // safe cast: values are stored internally keyed by AttributeKey<T>
@Override
@Nullable
public <T> T get(AttributeKey<T> key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value) {

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
// Safe: Attributes guarantees iteration over matching AttributeKey<T> / value pairs.
// Raw types are used here to avoid additional allocations while copying entries.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generic types don't survive into compiled code, so this has nothing to do with allocations that I know of.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generic types don't survive into compiled code, so this has nothing to do with allocations that I know of.

Good catch, thanks for pointing that out. You're right, the allocation comment isn't accurate here. I'll update the comment to focus only on the type-safety guarantee.

public AttributesBuilder putAll(Attributes attributes) {
if (attributes == null) {
return this;
}
// Attributes must iterate over their entries with matching types for key / value, so this
// downcast to the raw type is safe.
attributes.forEach((key, value) -> put((AttributeKey) key, value));
return this;
}
Expand Down
Loading