1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! `LuaString` — Lua's byte-string (NOT UTF-8). PORT_STRATEGY §3.3.
//!
//! Phase A-C: a simple `Box<[u8]>`-backed struct with a short/long flag.
//! Phase D may revisit for interning + content-hash equality.
/// Lua's immutable byte-string value.
///
/// The byte payload is a `Box<[u8]>`, NOT an `Rc<[u8]>`. Strings are immutable
/// and GC-owned: every live `LuaString` is reached through a `GcRef<LuaString>`
/// (the interner stores `GcRef`s, `LuaValue::Str` holds a `GcRef`), and all
/// value-level sharing happens at that `GcRef` layer. An `Rc<[u8]>` would
/// co-locate a 16-byte refcount header (strong + weak counts) with the payload
/// in the string's heap allocation, so every string allocation paid those 16
/// bytes on top of its `GcBox<LuaString>` for a refcount machinery nothing
/// uses. Switching to `Box<[u8]>` drops the 16-byte header per string and the
/// refcount inc/dec traffic; the win is in the heap allocation, not the struct
/// field (both `Rc<[u8]>` and `Box<[u8]>` are 16-byte fat pointers).
///
/// The `#[derive(Clone)]` is retained, but a by-value `LuaString` clone is now
/// a deep copy (alloc + memcpy) rather than a refcount bump. This is acceptable
/// because no hot path clones a `LuaString` by value — hot sharing goes through
/// the `Copy` `GcRef<LuaString>` handle. The only by-value clones are cold
/// (error-message construction, `GlobalState` init).
// ──────────────────────────────────────────────────────────────────────────────
// PORT STATUS
// source: src/lstring.h, src/lstring.c (TString)
// target_crate: lua-types
// confidence: high
// todos: 0
// port_notes: 0
// unsafe_blocks: 0
// notes: LuaString interned-string type. Mirrors C's TString with the short/long
// variant distinction and the hash field; uses GcRef-style ptr
// identity for interning. Byte payload is Box<[u8]>, not Rc<[u8]>:
// strings are immutable and shared at the GcRef level, so the Rc
// refcount header (16 B/string) was pure overhead. Box drops it.
// ──────────────────────────────────────────────────────────────────────────────