Refactor source cache into CachedFile struct (#12240)

# Description
Get rid of two parallel `Vec`s in `StateDelta` and `EngineState`, that
also duplicated span information. Use a struct with documenting fields.

Also use `Arc<str>` and `Arc<[u8]>` for the allocations as they are
never modified and cloned often (see #12229 for the first improvement).
This also makes the representation more compact as no capacity is
necessary.

# User-Facing Changes
API breakage on `EngineState`/`StateWorkingSet`/`StateDelta` that should
not really affect plugin authors.
This commit is contained in:
Stefan Holderbach
2024-03-20 19:43:50 +01:00
committed by GitHub
parent 63335e99ae
commit ec528c0626
10 changed files with 133 additions and 104 deletions

View File

@ -43,13 +43,15 @@ impl Command for ViewFiles {
) -> Result<PipelineData, ShellError> {
let mut records = vec![];
for (file, start, end) in engine_state.files() {
for file in engine_state.files() {
let start = file.covered_span.start;
let end = file.covered_span.end;
records.push(Value::record(
record! {
"filename" => Value::string(&**file, call.head),
"start" => Value::int(*start as i64, call.head),
"end" => Value::int(*end as i64, call.head),
"size" => Value::int(*end as i64 - *start as i64, call.head),
"filename" => Value::string(&*file.name, call.head),
"start" => Value::int(start as i64, call.head),
"end" => Value::int(end as i64, call.head),
"size" => Value::int(end as i64 - start as i64, call.head),
},
call.head,
));