Skip to content

Commit

Permalink
Merge pull request #917 from schungx/master
Browse files Browse the repository at this point in the history
Avoid unwrap
  • Loading branch information
schungx authored Sep 25, 2024
2 parents af3f00e + 134d832 commit ef3df63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
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

0 comments on commit ef3df63

Please sign in to comment.