Remove Arc from environment::globals() (take 2)

We don't forward this variable for storage in any structs, so there's no reason
to go through an Arc instead of returning the `&'static EnvStack` directly.

NB: This particular change was safe, and passes all tests on its own.
This commit is contained in:
Mahmoud Al-Qudsi 2024-05-16 20:50:23 -05:00
parent 45e249dd94
commit 3d648e6e04
5 changed files with 7 additions and 7 deletions

View file

@ -990,7 +990,7 @@ fn throwing_main() -> i32 {
}
}
OutputType::Ansi => {
colored_output = colorize(&output_wtext, &colors, &**EnvStack::globals());
colored_output = colorize(&output_wtext, &colors, EnvStack::globals());
}
OutputType::Html => {
colored_output = html_colorize(&output_wtext, &colors);

View file

@ -2473,7 +2473,7 @@ pub fn complete_load(cmd: &wstr, parser: &Parser) -> bool {
let path_to_load = completion_autoloader
.lock()
.expect("mutex poisoned")
.resolve_command(cmd, &**EnvStack::globals());
.resolve_command(cmd, EnvStack::globals());
if let Some(path_to_load) = path_to_load {
Autoload::perform_autoload(&path_to_load, parser);
completion_autoloader

View file

@ -360,10 +360,10 @@ impl EnvStack {
/// A variable stack that only represents globals.
/// Do not push or pop from this.
pub fn globals() -> &'static Arc<EnvStack> {
pub fn globals() -> &'static EnvStack {
use std::sync::OnceLock;
static GLOBALS: OnceLock<Arc<EnvStack>> = OnceLock::new();
&GLOBALS.get_or_init(|| Arc::new(EnvStack::new()))
static GLOBALS: OnceLock<EnvStack> = OnceLock::new();
GLOBALS.get_or_init(|| EnvStack::new())
}
/// Access the principal variable stack, associated with the principal parser.

View file

@ -122,7 +122,7 @@ pub fn load(name: &wstr, parser: &Parser) -> bool {
if funcset.allow_autoload(name) {
if let Some(path) = funcset
.autoloader
.resolve_command(name, &**EnvStack::globals())
.resolve_command(name, EnvStack::globals())
{
path_to_autoload = Some(path);
}

View file

@ -65,7 +65,7 @@ impl<'a> OperationContext<'a> {
// Return an operation context that contains only global variables, no parser, and never
// cancels.
pub fn globals() -> OperationContext<'static> {
OperationContext::background(&**EnvStack::globals(), EXPANSION_LIMIT_DEFAULT)
OperationContext::background(EnvStack::globals(), EXPANSION_LIMIT_DEFAULT)
}
/// Construct from a full set of properties.