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 -->
This commit is contained in:
bors-servo 2015-06-12 15:00:37 -06:00
commit 2168ec3c96

View file

@ -134,19 +134,15 @@ impl<T: ClipboardProvider> TextInput<T> {
/// Insert a character at the current editing point /// Insert a character at the current editing point
pub fn insert_char(&mut self, ch: char) { pub fn insert_char(&mut self, ch: char) {
if self.selection_begin.is_none() { self.insert_string(ch.to_string());
self.selection_begin = Some(self.edit_point);
}
self.replace_selection(ch.to_string());
} }
/// Insert a string at the current editing point /// Insert a string at the current editing point
fn insert_string(&mut self, s: &str) { fn insert_string<S: Into<String>>(&mut self, s: S) {
// it looks like this could be made performant by avoiding some redundant if self.selection_begin.is_none() {
// selection-related checks, but use the simple implementation for now self.selection_begin = Some(self.edit_point);
for ch in s.chars() {
self.insert_char(ch);
} }
self.replace_selection(s.into());
} }
pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) { pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
@ -316,7 +312,7 @@ impl<T: ClipboardProvider> TextInput<T> {
}, },
Key::V if is_control_key(mods) => { Key::V if is_control_key(mods) => {
let contents = self.clipboard_provider.clipboard_contents(); let contents = self.clipboard_provider.clipboard_contents();
self.insert_string(&contents); self.insert_string(contents);
KeyReaction::DispatchInput KeyReaction::DispatchInput
}, },
_ if is_printable_key(key) => { _ if is_printable_key(key) => {