Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Oct 14, 2023
1 parent e4b329b commit 34f24aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 2 additions & 5 deletions melior/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ impl Context {
unsafe { mlirContextDetachDiagnosticHandler(self.to_raw(), id.to_raw()) }
}

pub(crate) fn create_c_string(&self, string: &str) -> &CString {
self.string_cache
.entry(CString::new(string).unwrap())
.or_insert_with(Default::default)
.key()
pub(crate) fn string_cache(&self) -> &DashMap<CString, ()> {
&self.string_cache
}
}

Expand Down
8 changes: 7 additions & 1 deletion melior/src/string_ref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::Context;
use mlir_sys::{mlirStringRefCreateFromCString, mlirStringRefEqual, MlirStringRef};
use std::{
ffi::CString,
marker::PhantomData,
slice,
str::{self, Utf8Error},
Expand All @@ -19,7 +20,12 @@ pub struct StringRef<'c> {

impl<'c> StringRef<'c> {
pub fn from_str(context: &'c Context, string: &str) -> Self {
let string = context.create_c_string(string).as_ptr();
let string = context
.string_cache()
.entry(CString::new(string).unwrap())
.or_insert_with(Default::default)
.key()
.as_ptr();

unsafe { Self::from_raw(mlirStringRefCreateFromCString(string)) }
}
Expand Down

0 comments on commit 34f24aa

Please sign in to comment.