Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overwriting references from users #30

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

Genbox
Copy link
Contributor

@Genbox Genbox commented Jan 21, 2024

SqidOptions is provided by the user. Adding/removing items or overwriting the reference can have unintended side effects in the user's application. In this PR I simply create a local HashSet, copy over the user's data (while skipping invalid entries) and convert it to a local array at the end.

We now also avoid removal from the HashSet giving a small perf boost
@aradalvand
Copy link
Collaborator

aradalvand commented Jan 30, 2024

Sorry for the delay, @Genbox. Thanks for the PR.

We are not actually mutating the HashSet instance the user gives us; the very first thing we do is we replace options.BlockList with a new HashSet instance while copying over elements from the user-provided HashSet, and then modifying this new HashSet:

options.BlockList = new HashSet<string>(
options.BlockList,

So, I'm not sure what the problem is here?

@aradalvand
Copy link
Collaborator

aradalvand commented Jan 30, 2024

Ah I see what you mean now, you're talking about us mutating the SqidsOptions instance. That's valid.
Your implementation is also better in that it results in a single iteration over the user-provided HashSet, as opposed to two (under the hood) iterations in the current implementation (once by the HashSet constructor and then once more by .RemoveWhere()). Strange that I'd missed that!

@aradalvand aradalvand merged commit 8170f81 into sqids:main Jan 30, 2024
1 check passed
@aradalvand
Copy link
Collaborator

@Genbox Thank you!

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.

2 participants