Avoid another &Lrc<..> in a return value.

This commit is contained in:
Nicholas Nethercote 2024-10-07 13:25:38 +11:00
parent 2123509351
commit 4547c0a990
3 changed files with 3 additions and 2 deletions

View File

@ -1380,7 +1380,7 @@ pub enum ExternalSourceKind {
} }
impl ExternalSource { impl ExternalSource {
pub fn get_source(&self) -> Option<&Lrc<String>> { pub fn get_source(&self) -> Option<&str> {
match self { match self {
ExternalSource::Foreign { kind: ExternalSourceKind::Present(ref src), .. } => Some(src), ExternalSource::Foreign { kind: ExternalSourceKind::Present(ref src), .. } => Some(src),
_ => None, _ => None,

View File

@ -257,7 +257,7 @@ fn t10() {
); );
imported_src_file.add_external_src(|| Some(unnormalized.to_string())); imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
assert_eq!( assert_eq!(
imported_src_file.external_src.borrow().get_source().unwrap().as_ref(), imported_src_file.external_src.borrow().get_source().unwrap(),
normalized, normalized,
"imported source file should be normalized" "imported source file should be normalized"
); );

View File

@ -287,6 +287,7 @@ pub fn as_str(&self) -> Option<&str> {
self.sf self.sf
.src .src
.as_ref() .as_ref()
.map(|src| src.as_str())
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source())) .or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
.and_then(|x| x.get(self.range.clone())) .and_then(|x| x.get(self.range.clone()))
} }