small speed optimization

This commit is contained in:
daa 2017-03-07 14:36:29 +03:00
parent a9adeb648f
commit df496e2d27

View File

@ -55,7 +55,7 @@ pub struct Ui {
mode: NvimMode, mode: NvimMode,
mouse_enabled: bool, mouse_enabled: bool,
mouse_pressed: bool, mouse_pressed: bool,
font_desc: String, font_desc: FontDescription,
} }
impl Ui { impl Ui {
@ -74,7 +74,7 @@ impl Ui {
mode: NvimMode::Normal, mode: NvimMode::Normal,
mouse_enabled: false, mouse_enabled: false,
mouse_pressed: false, mouse_pressed: false,
font_desc: FONT_NAME.to_owned(), font_desc: FontDescription::from_string(FONT_NAME),
} }
} }
@ -136,11 +136,11 @@ impl Ui {
} }
fn create_pango_font(&self) -> FontDescription { fn create_pango_font(&self) -> FontDescription {
FontDescription::from_string(&self.font_desc) self.font_desc.clone()
} }
fn set_font_desc(&mut self, desc: &str) { fn set_font_desc(&mut self, desc: &str) {
self.font_desc = desc.to_owned(); self.font_desc = FontDescription::from_string(desc);
} }
} }
@ -290,6 +290,7 @@ fn draw(ui: &Ui, ctx: &cairo::Context) {
let layout = pc::create_layout(ctx); let layout = pc::create_layout(ctx);
let mut desc = ui.create_pango_font();
for (line_idx, line) in ui.model.model().iter().enumerate() { for (line_idx, line) in ui.model.model().iter().enumerate() {
ctx.move_to(0.0, line_y); ctx.move_to(0.0, line_y);
@ -332,7 +333,7 @@ fn draw(ui: &Ui, ctx: &cairo::Context) {
} }
if !cell.ch.is_whitespace() { if !cell.ch.is_whitespace() {
let mut desc = ui.create_pango_font(); desc.unset_fields(pango::FONT_MASK_STYLE | pango::FONT_MASK_WEIGHT);
if cell.attrs.italic { if cell.attrs.italic {
desc.set_style(pango::Style::Italic); desc.set_style(pango::Style::Italic);
} }