From 49d6133f22e295408f3dab7d482b74a2a6387b13 Mon Sep 17 00:00:00 2001
From: Michael Aaron Murphy <mmstickman@gmail.com>
Date: Thu, 12 Oct 2017 19:48:19 -0400
Subject: [PATCH] get_vars() now returns an iterator

Since we are depending on Nightly, we may as well utilize the impl
trait return type feature that should help us to avoid some heap
allocations when getting a list of variables in the shell.
---
 src/shell/binary.rs        | 6 +++---
 src/shell/variables/mod.rs | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/shell/binary.rs b/src/shell/binary.rs
index f0a55dd7..4a8e12e4 100644
--- a/src/shell/binary.rs
+++ b/src/shell/binary.rs
@@ -161,7 +161,7 @@ impl<'a> Binary for Shell<'a> {
                                 // Add the list of available variables to the completer's definitions.
                                 // TODO: We should make it free to do String->SmallString
                                 //       and mostly free to go back (free if allocated)
-                                .chain(vars.get_vars().into_iter().map(|s| ["$", &s].concat().into()))
+                                .chain(vars.get_vars().map(|s| ["$", &s].concat().into()))
                                 .collect();
 
                                 // Initialize a new completer from the definitions collected.
@@ -441,11 +441,11 @@ fn complete_as_file(current_dir: PathBuf, filename: String, index: usize) -> boo
     let mut file = current_dir.clone();
     file.push(&filename);
     // If the user explicitly requests a file through this syntax then complete as a file
-    if filename.trim().starts_with(".") {
+    if filename.starts_with(".") {
         return true;
     }
     // If the file starts with a dollar sign, it's a variable, not a file
-    if filename.trim().starts_with("$") {
+    if filename.starts_with("$") {
         return false;
     }
     // Once we are beyond the first string, assume its a file
diff --git a/src/shell/variables/mod.rs b/src/shell/variables/mod.rs
index fad2012c..5cd382db 100644
--- a/src/shell/variables/mod.rs
+++ b/src/shell/variables/mod.rs
@@ -257,8 +257,8 @@ impl Variables {
 
     pub fn unset_var(&mut self, name: &str) -> Option<Value> { self.variables.remove(name) }
 
-    pub fn get_vars(&self) -> Vec<Identifier> {
-        self.variables.keys().cloned().chain(env::vars().map(|(k, _)| k.into())).collect()
+    pub fn get_vars<'a>(&'a self) -> impl Iterator<Item = Identifier> + 'a {
+        self.variables.keys().cloned().chain(env::vars().map(|(k, _)| k.into()))
     }
 
     pub(crate) fn is_valid_variable_character(c: char) -> bool {
-- 
GitLab