module scheme // Only a prefix creates fresh names in the transform pass. Provider and // explicit rename names are borrowed. A full prefix needs no per-row sidecar; // materialize flags only when filtering/renaming divides that ownership. struct ImportNameOwnership { mut: all bool flags []bool } fn import_selection_name_flags(capacity int) []bool { mut flags := []bool{cap: capacity} unsafe { flags.flags.set(.noslices) } return flags } @[inline] fn (names &ImportNameOwnership) owns(index int) bool { return names.all || (names.flags.len > 0 && names.flags[index]) } fn (mut names ImportNameOwnership) discard(index int, name string, count int) { if !names.owns(index) { return } if names.all { names.flags = filled_storage(count, true) names.all = false } container_store_validated(mut names.flags, index, false) mut owned := name unsafe { owned.free() } } fn (mut names ImportNameOwnership) release_metadata() { unsafe { names.flags.free() } names.flags = []bool{} names.all = false } fn (mut names ImportNameOwnership) release[T](items []T) { if names.all || names.flags.len > 0 { for i, item in items { if names.owns(i) { mut owned := item.name unsafe { owned.free() } } } } names.release_metadata() } fn prefixed_import_name(prefix string, name string) string { // The pinned concat implementation always allocates, even for an empty // operand. Encoding a leading NUL makes another fresh allocation. mut joined := prefix + external_identifier_spelling(name) encoded := external_identifier_key(joined) if encoded.str != joined.str { unsafe { joined.free() } } return encoded }