fix(advanced_table): Use std.mem.swap for Row sorting + doc warnings
- Replace manual temp variable swap with std.mem.swap (more explicit) - Add documentation warning about pointer invalidation after sort/setRows - Row contains StringHashMap with internal pointers - swap is safe but pointers obtained via getRow() are invalidated after mutations Based on INFORME_AUDITORIA_PROFUNDA_20251225.md §1.2
This commit is contained in:
parent
1c284ed0f6
commit
7f8870d890
2 changed files with 9 additions and 4 deletions
|
|
@ -1243,10 +1243,11 @@ fn sortRows(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (should_swap) {
|
if (should_swap) {
|
||||||
// Swap rows
|
// Swap rows usando std.mem.swap (seguro para structs con punteros internos)
|
||||||
const temp = table_state.rows.items[i];
|
// NOTA: Row contiene StringHashMap que tiene punteros a buckets.
|
||||||
table_state.rows.items[i] = table_state.rows.items[i + 1];
|
// El swap mueve el struct completo, no clona los datos.
|
||||||
table_state.rows.items[i + 1] = temp;
|
// Los punteros obtenidos via getRow() se invalidan tras sort.
|
||||||
|
std.mem.swap(Row, &table_state.rows.items[i], &table_state.rows.items[i + 1]);
|
||||||
|
|
||||||
// Swap state map entries
|
// Swap state map entries
|
||||||
swapRowStates(table_state, i, i + 1);
|
swapRowStates(table_state, i, i + 1);
|
||||||
|
|
|
||||||
|
|
@ -231,12 +231,16 @@ pub const AdvancedTableState = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get row by index
|
/// Get row by index
|
||||||
|
/// ADVERTENCIA: El puntero retornado se invalida tras sortRows() o setRows().
|
||||||
|
/// No guardar el puntero entre frames - obtenerlo de nuevo cuando sea necesario.
|
||||||
pub fn getRow(self: *AdvancedTableState, index: usize) ?*Row {
|
pub fn getRow(self: *AdvancedTableState, index: usize) ?*Row {
|
||||||
if (index >= self.rows.items.len) return null;
|
if (index >= self.rows.items.len) return null;
|
||||||
return &self.rows.items[index];
|
return &self.rows.items[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get row by index (const)
|
/// Get row by index (const)
|
||||||
|
/// ADVERTENCIA: El puntero retornado se invalida tras sortRows() o setRows().
|
||||||
|
/// No guardar el puntero entre frames - obtenerlo de nuevo cuando sea necesario.
|
||||||
pub fn getRowConst(self: *const AdvancedTableState, index: usize) ?*const Row {
|
pub fn getRowConst(self: *const AdvancedTableState, index: usize) ?*const Row {
|
||||||
if (index >= self.rows.items.len) return null;
|
if (index >= self.rows.items.len) return null;
|
||||||
return &self.rows.items[index];
|
return &self.rows.items[index];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue