diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-06-12 15:00:37 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-06-12 15:00:37 -0600 |
commit | 2168ec3c96ca9e8e1174be22be07d1168061b4b6 (patch) | |
tree | 86cd3e6cd0aabfdcaa664ebe84d9497fa1da4c66 /components | |
parent | c8c7bd900dde73d4fddafea8239f44440f1c863b (diff) | |
parent | b1486720e9c160286fb0644e559cb9bd0d207281 (diff) | |
download | servo-2168ec3c96ca9e8e1174be22be07d1168061b4b6.tar.gz servo-2168ec3c96ca9e8e1174be22be07d1168061b4b6.zip |
Auto merge of #6340 - aweinstock314:reduce-textinput-allocations, r=Ms2ger
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6340)
<!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r-- | components/script/textinput.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 59d6752daef..8d5668e1d04 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -134,19 +134,15 @@ impl<T: ClipboardProvider> TextInput<T> { /// Insert a character at the current editing point pub fn insert_char(&mut self, ch: char) { - if self.selection_begin.is_none() { - self.selection_begin = Some(self.edit_point); - } - self.replace_selection(ch.to_string()); + self.insert_string(ch.to_string()); } /// Insert a string at the current editing point - fn insert_string(&mut self, s: &str) { - // it looks like this could be made performant by avoiding some redundant - // selection-related checks, but use the simple implementation for now - for ch in s.chars() { - self.insert_char(ch); + fn insert_string<S: Into<String>>(&mut self, s: S) { + if self.selection_begin.is_none() { + self.selection_begin = Some(self.edit_point); } + self.replace_selection(s.into()); } pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) { @@ -316,7 +312,7 @@ impl<T: ClipboardProvider> TextInput<T> { }, Key::V if is_control_key(mods) => { let contents = self.clipboard_provider.clipboard_contents(); - self.insert_string(&contents); + self.insert_string(contents); KeyReaction::DispatchInput }, _ if is_printable_key(key) => { |