aboutsummaryrefslogtreecommitdiff
path: root/src/grid/row.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-01-14 10:17:08 -0800
committerJoe Wilm <joe@jwilm.com>2018-03-07 09:46:18 -0800
commitc954b6cb92672970293424d60e2a829b626a41d3 (patch)
tree8a878627694bd78eb7cef25a65f099174c355944 /src/grid/row.rs
parent2612c9b6944491fc37be8427493ad80b914698ae (diff)
downloadalacritty-c954b6cb92672970293424d60e2a829b626a41d3.tar.gz
alacritty-c954b6cb92672970293424d60e2a829b626a41d3.zip
Use memcpy for resetting row contents
In addition to a marginal performance improvement, this simplifies some logic in the Term implementation since now the Grid fully handles row recycling.
Diffstat (limited to 'src/grid/row.rs')
-rw-r--r--src/grid/row.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/grid/row.rs b/src/grid/row.rs
index 4b355a56..e9cf8dc9 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -24,16 +24,22 @@ use index::Column;
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct Row<T>(Vec<T>);
-impl<T: Clone> Row<T> {
+impl<T: Copy + Clone> Row<T> {
pub fn new(columns: Column, template: &T) -> Row<T> {
- Row(vec![template.to_owned(); *columns])
+ Row(vec![*template; *columns])
}
pub fn grow(&mut self, cols: Column, template: &T) {
while self.len() != *cols {
- self.push(template.to_owned());
+ self.push(*template);
}
}
+
+ /// Resets contents to the contents of `other`
+ #[inline]
+ pub fn reset(&mut self, other: &Row<T>) {
+ self.copy_from_slice(&**other);
+ }
}
impl<T> Row<T> {