Skip to content

OAK-11605 : removed usage of Guava's ImmutableSet.copyOf with LinkedSet#2184

Merged
rishabhdaim merged 1 commit intotrunkfrom
OAK-11605
Mar 24, 2025
Merged

OAK-11605 : removed usage of Guava's ImmutableSet.copyOf with LinkedSet#2184
rishabhdaim merged 1 commit intotrunkfrom
OAK-11605

Conversation

@rishabhdaim
Copy link
Contributor

No description provided.

@github-actions
Copy link

Commit-Check ✔️

Set<String> filesToBeDeleted =
// Files present locally
ImmutableSet.copyOf(local.listAll()).stream()
SetUtils.toLinkedSet(local.listAll()).stream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are simply iterating over Set, so there is no need for immutability here.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also no need to create a null-safe set as we do not do any look-up, so I think we can just remove the call to ImmutableSet.copyOf(). The set created by the stream is already immutable, so this call to Guava seems to be redundant.

Copy link
Contributor Author

@rishabhdaim rishabhdaim Mar 17, 2025

Choose a reason for hiding this comment

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

ImmutableSet.copyOf() is called to convert the array returned by local.listAll() to a collection, and then run stream operations on it.

It's either convert this to a collection OR use Arrays.stream(local.listAll()).
I don't have any strong opinion.

Set<String> filesToBeDeleted =
// Files present locally
ImmutableSet.copyOf(local.listAll()).stream()
SetUtils.toLinkedSet(local.listAll()).stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also no need to create a null-safe set as we do not do any look-up, so I think we can just remove the call to ImmutableSet.copyOf(). The set created by the stream is already immutable, so this call to Guava seems to be redundant.

fileNames = directoryBuilder.getChildNodeNames();
}
Set<String> result = ImmutableSet.copyOf(fileNames);
Set<String> result = Collections.unmodifiableSet(SetUtils.toLinkedSet(fileNames));
Copy link
Contributor

Choose a reason for hiding this comment

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

Also no need for immutability of null-safe lookups. This method is called only from the constructor, which just iterates over the contents of the set to add it to another set. I think this could be simplified. Directory listings may be long, so it may be worth to avoid copies here if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather keep the optimizations separate from this ticket.
In this PR, I would try to keep the behavior as close as possible to the original.

@rishabhdaim rishabhdaim merged commit dea4054 into trunk Mar 24, 2025
2 of 3 checks passed
@rishabhdaim rishabhdaim deleted the OAK-11605 branch March 24, 2025 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants