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 unwrap #917

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug fixes

* (Fuzzing) An integer-overflow bug from an inclusive range in the bits iterator is fixed.
* (Fuzzing) An integer-underflow bug from an inclusive range is fixed.
* Copy strings if the strings interner is busy instead of panicing.

New features
------------
Expand Down
27 changes: 16 additions & 11 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ impl Engine {
string: impl AsRef<str> + Into<ImmutableString>,
) -> ImmutableString {
match self.interned_strings {
Some(ref interner) => locked_write(interner).unwrap().get(string),
Some(ref interner) => match locked_write(interner) {
Some(mut cache) => cache.get(string),
None => string.into(),
},
None => string.into(),
}
}
Expand All @@ -357,11 +360,12 @@ impl Engine {
text: impl AsRef<str> + Into<ImmutableString>,
) -> ImmutableString {
match self.interned_strings {
Some(ref interner) => locked_write(interner).unwrap().get_with_mapper(
b'g',
|s| make_getter(s.as_ref()).into(),
text,
),
Some(ref interner) => match locked_write(interner) {
Some(mut cache) => {
cache.get_with_mapper(b'g', |s| make_getter(s.as_ref()).into(), text)
}
None => make_getter(text.as_ref()).into(),
},
None => make_getter(text.as_ref()).into(),
}
}
Expand All @@ -375,11 +379,12 @@ impl Engine {
text: impl AsRef<str> + Into<ImmutableString>,
) -> ImmutableString {
match self.interned_strings {
Some(ref interner) => locked_write(interner).unwrap().get_with_mapper(
b's',
|s| make_setter(s.as_ref()).into(),
text,
),
Some(ref interner) => match locked_write(interner) {
Some(mut cache) => {
cache.get_with_mapper(b's', |s| make_setter(s.as_ref()).into(), text)
}
None => make_setter(text.as_ref()).into(),
},
None => make_setter(text.as_ref()).into(),
}
}
Expand Down
Loading