aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorath32022-11-15 14:14:18 +0000
committerGitHub2022-11-15 14:14:18 +0000
commit3b7760dfb0cdb547ff8c94f7685554f59d16bf0a (patch)
treec784151672c626a6c04fb811a7611a6603683fec /helix-core/src
parent652497bdd613d2854f63a1e99e9625a21a007389 (diff)
Refactor blackhole register (#4504)
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/register.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs
index 1cff77ba..52eb6e3e 100644
--- a/helix-core/src/register.rs
+++ b/helix-core/src/register.rs
@@ -15,11 +15,7 @@ impl Register {
}
pub fn new_with_values(name: char, values: Vec<String>) -> Self {
- if name == '_' {
- Self::new(name)
- } else {
- Self { name, values }
- }
+ Self { name, values }
}
pub const fn name(&self) -> char {
@@ -31,15 +27,11 @@ impl Register {
}
pub fn write(&mut self, values: Vec<String>) {
- if self.name != '_' {
- self.values = values;
- }
+ self.values = values;
}
pub fn push(&mut self, value: String) {
- if self.name != '_' {
- self.values.push(value);
- }
+ self.values.push(value);
}
}
@@ -54,19 +46,25 @@ impl Registers {
self.inner.get(&name)
}
- pub fn get_mut(&mut self, name: char) -> &mut Register {
- self.inner
- .entry(name)
- .or_insert_with(|| Register::new(name))
+ pub fn read(&self, name: char) -> Option<&[String]> {
+ self.get(name).map(|reg| reg.read())
}
pub fn write(&mut self, name: char, values: Vec<String>) {
- self.inner
- .insert(name, Register::new_with_values(name, values));
+ if name != '_' {
+ self.inner
+ .insert(name, Register::new_with_values(name, values));
+ }
}
- pub fn read(&self, name: char) -> Option<&[String]> {
- self.get(name).map(|reg| reg.read())
+ pub fn push(&mut self, name: char, value: String) {
+ if name != '_' {
+ if let Some(r) = self.inner.get_mut(&name) {
+ r.push(value);
+ } else {
+ self.write(name, vec![value]);
+ }
+ }
}
pub fn first(&self, name: char) -> Option<&String> {