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-01-14 10:17:08 -0800
commitd0a1ff47367193d1cc3947d0599489f6ce7091cb (patch)
treebd52f1d112dc708c21f64177b2d92f3160580442 /src/grid/row.rs
parent44f58b81f296ac1f3a73f93c35537c4b531bb5d7 (diff)
downloadalacritty-d0a1ff47367193d1cc3947d0599489f6ce7091cb.tar.gz
alacritty-d0a1ff47367193d1cc3947d0599489f6ce7091cb.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> {