nushell/crates/nu-protocol/src/engine/cached_file.rs
Stefan Holderbach ec528c0626
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.
2024-03-20 19:43:50 +01:00

15 lines
506 B
Rust

use crate::Span;
use std::sync::Arc;
/// Unit of cached source code
#[derive(Clone)]
pub struct CachedFile {
// Use Arcs of slice types for more compact representation (capacity less)
// Could possibly become an `Arc<PathBuf>`
/// The file name with which the code is associated (also includes REPL input)
pub name: Arc<str>,
/// Source code as raw bytes
pub content: Arc<[u8]>,
/// global span coordinates that are covered by this [`CachedFile`]
pub covered_span: Span,
}