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

Repurpose Result #216

Merged
merged 2 commits into from
Jan 25, 2025
Merged

Repurpose Result #216

merged 2 commits into from
Jan 25, 2025

Conversation

rovarga
Copy link
Collaborator

@rovarga rovarga commented Jan 23, 2025

Redesign this class to do what LookupResult used to do -- be just a
singleton indicator of restart. This allows us to ditch object
allocation from insert return paths.

Signed-off-by: Robert Varga [email protected]

The design of Result comes from original code as a replacement for
Optional. The thing is: we do not allow storage of nulls, hence we do
not have a use for a Optional.ofNullable() equivalent and therefore end
up allocating a result based on LNode/SNode value.

Make Result an enum with a single value RESTART, replacing
TrieMap.RESTART, just like we have had for LookupResult and switch
to using it for both lookup and insert cases.

The conversion is:
- null becomes 'RESTART' (with a static import)
- Result.empty() becomes 'null'
- Result.isPresent() becomes '!= null'
- Result.orNull() becomes nothing

Signed-off-by: Robert Varga <[email protected]>
The if/return check can be simplified into an expression, let's take
advantage of that.

Signed-off-by: Robert Varga <[email protected]>
@rovarga rovarga merged commit 0842609 into PANTHEONtech:master Jan 25, 2025
2 checks passed
@rovarga rovarga deleted the no-result branch January 25, 2025 02:52
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.

1 participant