pub(crate) fn new_static_string(
        &self,
        span: Span,
        current: &str,
    ) -> Result<usize, CompileError> {
        let mut inner = self.inner.borrow_mut();

        let current = StaticString::new(current);
        let hash = current.hash();

        if let Some(existing_slot) = inner.static_string_rev.get(&hash).copied() {
            let existing = inner.static_strings.get(existing_slot).ok_or_else(|| {
                CompileError::new(
                    span,
                    CompileErrorKind::StaticStringMissing {
                        hash,
                        slot: existing_slot,
                    },
                )
            })?;

            if ***existing != *current {
                return Err(CompileError::new(
                    span,
                    CompileErrorKind::StaticStringHashConflict {
                        hash,
                        current: (*current).clone(),
                        existing: (***existing).clone(),
                    },
                ));
            }

            return Ok(existing_slot);
        }

        let new_slot = inner.static_strings.len();
        inner.static_strings.push(Arc::new(current));
        inner.static_string_rev.insert(hash, new_slot);
        Ok(new_slot)
    }
/// Insert a static string and return its associated slot that can later be
/// looked up through [lookup_string][Unit::lookup_string].
///
/// Only uses up space if the static string is unique.
Insert a static string and return its associated slot that can later be
looked up through [lookup_string][Unit::lookup_string].

Only uses up space if the static string is unique.
Insert a static string and return its associated slot that can later be looked up through [ lookup_string ] [ Unit :: lookup_string ] . Only uses up space if the static string is unique .
pub(crate) fn new_static_string(
        &self,
        span: Span,
        current: &str,
    ) -> Result<usize, CompileError> {
        let mut inner = self.inner.borrow_mut();
        let current = StaticString::new(current);
        let hash = current.hash();
        if let Some(existing_slot) = inner.static_string_rev.get(&hash).copied() {
            let existing = inner.static_strings.get(existing_slot).ok_or_else(|| {
                CompileError::new(
                    span,
                    CompileErrorKind::StaticStringMissing {
                        hash,
                        slot: existing_slot,
                    },
                )
            })?;
            if ***existing != *current {
                return Err(CompileError::new(
                    span,
                    CompileErrorKind::StaticStringHashConflict {
                        hash,
                        current: (*current).clone(),
                        existing: (***existing).clone(),
                    },
                ));
            }
            return Ok(existing_slot);
        }
        let new_slot = inner.static_strings.len();
        inner.static_strings.push(Arc::new(current));
        inner.static_string_rev.insert(hash, new_slot);
        Ok(new_slot)
    }
pub ( crate ) fn new_static_string ( & self , span : Span , current : & str , ) -> Result < usize , CompileError > { let mut inner = self . inner . borrow_mut ( ) ; let current = StaticString :: new ( current ) ; let hash = current . hash ( ) ; if let Some ( existing_slot ) = inner . static_string_rev . get ( & hash ) . copied ( ) { let existing = inner . static_strings . get ( existing_slot ) . ok_or_else ( | | { CompileError :: new ( span , CompileErrorKind :: StaticStringMissing { hash , slot : existing_slot , } , ) } ) ? ; if * * * existing != * current { return Err ( CompileError :: new ( span , CompileErrorKind :: StaticStringHashConflict { hash , current : ( * current ) . clone ( ) , existing : ( * * * existing ) . clone ( ) , } , ) ) ; } return Ok ( existing_slot ) ; } let new_slot = inner . static_strings . len ( ) ; inner . static_strings . push ( Arc :: new ( current ) ) ; inner . static_string_rev . insert ( hash , new_slot ) ; Ok ( new_slot ) }
Insert a static string and return its associated slot that can later be
looked up through [lookup_string][Unit::lookup_string].
Insert a static string and return its associated slot that can later be looked up through [ lookup_string ] [ Unit :: lookup_string ] .
&self
span
Span
current
&str
&self
span
Span
current
&str