@@ -35,9 +35,8 @@ use crate::{impl_shared_string_api, meta};
35
35
///
36
36
/// # Performance
37
37
///
38
- /// The fastest way to create string names is by using null-terminated C-string literals such as `c"MyClass"`. These have `'static` lifetime and
39
- /// can be used directly by Godot, without allocation or conversion. The encoding is limited to Latin-1, however. See the corresponding
40
- /// [`From<&'static CStr>` impl](#impl-From<%26CStr>-for-StringName).
38
+ /// The fastest way to create string names is by using null-terminated C-string literals such as `c"MyClass"`. These can be used directly by Godot without conversion. The encoding is limited to Latin-1, however. See the corresponding
39
+ /// [`From<&CStr>` impl](#impl-From<%26CStr>-for-StringName).
41
40
///
42
41
/// # All string types
43
42
///
@@ -249,11 +248,6 @@ impl StringName {
249
248
pub fn as_inner ( & self ) -> inner:: InnerStringName < ' _ > {
250
249
inner:: InnerStringName :: from_outer ( self )
251
250
}
252
-
253
- /// Increment ref-count. This may leak memory if used wrongly.
254
- fn inc_ref ( & self ) {
255
- std:: mem:: forget ( self . clone ( ) ) ;
256
- }
257
251
}
258
252
259
253
// SAFETY:
@@ -384,8 +378,8 @@ impl From<NodePath> for StringName {
384
378
}
385
379
}
386
380
387
- impl From < & ' static std:: ffi:: CStr > for StringName {
388
- /// Creates a `StringName` from a static ASCII/Latin-1 `c"string"`.
381
+ impl From < & std:: ffi:: CStr > for StringName {
382
+ /// Creates a `StringName` from a ASCII/Latin-1 `c"string"`.
389
383
///
390
384
/// This avoids unnecessary copies and allocations and directly uses the backing buffer. Useful for literals.
391
385
///
@@ -399,23 +393,17 @@ impl From<&'static std::ffi::CStr> for StringName {
399
393
/// // '±' is a Latin-1 character with codepoint 0xB1. Note that this is not UTF-8, where it would need two bytes.
400
394
/// let sname = StringName::from(c"\xb1 Latin-1 string");
401
395
/// ```
402
- fn from ( c_str : & ' static std:: ffi:: CStr ) -> Self {
396
+ fn from ( c_str : & std:: ffi:: CStr ) -> Self {
403
397
// SAFETY: c_str is nul-terminated and remains valid for entire program duration.
404
- let result = unsafe {
398
+ unsafe {
405
399
Self :: new_with_string_uninit ( |ptr| {
406
400
sys:: interface_fn!( string_name_new_with_latin1_chars) (
407
401
ptr,
408
402
c_str. as_ptr ( ) ,
409
- sys:: conv:: SYS_TRUE , // p_is_static
403
+ sys:: conv:: SYS_FALSE , // p_is_static
410
404
)
411
405
} )
412
- } ;
413
-
414
- // StringName expects that the destructor is not invoked on static instances (or only at global exit; see SNAME(..) macro in Godot).
415
- // According to testing with godot4 --verbose, there is no mention of "Orphan StringName" at shutdown when incrementing the ref-count,
416
- // so this should not leak memory.
417
- result. inc_ref ( ) ;
418
- result
406
+ }
419
407
}
420
408
}
421
409
0 commit comments