Switch to parking_lot::Mutex. It is faster and has a better API than the std one

Also, no possibility of poisoning, so it removes a bunch of unwraps
macos-click-through
Jon Valdés 5 years ago
parent 6db3f31c74
commit f9c7e2500c

1
Cargo.lock generated

@ -1234,6 +1234,7 @@ dependencies = [
"log", "log",
"lru", "lru",
"nvim-rs", "nvim-rs",
"parking_lot",
"rmpv", "rmpv",
"rust-embed", "rust-embed",
"skribo", "skribo",

@ -24,6 +24,7 @@ log = "0.4.8"
flexi_logger = { version = "0.14.6", default-features = false } flexi_logger = { version = "0.14.6", default-features = false }
anyhow = "1.0.26" anyhow = "1.0.26"
crossbeam = "0.7" crossbeam = "0.7"
parking_lot="0.10.0"
[build-dependencies] [build-dependencies]
winres = "0.1.11" winres = "0.1.11"

@ -20,7 +20,7 @@ impl NeovimHandler {
tokio::spawn(async move { tokio::spawn(async move {
while let Some(event) = receiver.recv().await { while let Some(event) = receiver.recv().await {
let mut editor = EDITOR.lock().unwrap(); let mut editor = EDITOR.lock();
editor.handle_redraw_event(event); editor.handle_redraw_event(event);
} }
}); });

@ -3,8 +3,9 @@ mod style;
mod grid; mod grid;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use skulpin::skia_safe::colors; use skulpin::skia_safe::colors;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use log::trace; use log::trace;

@ -179,7 +179,7 @@ impl CursorRenderer {
let render = self.blink_status.update_status(&cursor); let render = self.blink_status.update_status(&cursor);
self.previous_position = { self.previous_position = {
let editor = EDITOR.lock().unwrap(); let editor = EDITOR.lock();
let (_, grid_y) = cursor.position; let (_, grid_y) = cursor.position;
let (_, previous_y) = self.previous_position; let (_, previous_y) = self.previous_position;
if grid_y == editor.grid.height - 1 && previous_y != grid_y { if grid_y == editor.grid.height - 1 && previous_y != grid_y {
@ -199,7 +199,7 @@ impl CursorRenderer {
let (grid_x, grid_y) = self.previous_position; let (grid_x, grid_y) = self.previous_position;
let (character, font_dimensions): (String, Point) = { let (character, font_dimensions): (String, Point) = {
let editor = EDITOR.lock().unwrap(); let editor = EDITOR.lock();
let character = match editor.grid.get_cell(grid_x, grid_y) { let character = match editor.grid.get_cell(grid_x, grid_y) {
Some(Some((character, _))) => character.clone(), Some(Some((character, _))) => character.clone(),
_ => ' '.to_string(), _ => ' '.to_string(),

@ -101,7 +101,7 @@ impl Renderer {
pub fn draw(&mut self, gpu_canvas: &mut Canvas, coordinate_system_helper: &CoordinateSystemHelper) -> bool { pub fn draw(&mut self, gpu_canvas: &mut Canvas, coordinate_system_helper: &CoordinateSystemHelper) -> bool {
trace!("Rendering"); trace!("Rendering");
let ((draw_commands, should_clear), default_style, cursor, font_name, font_size) = { let ((draw_commands, should_clear), default_style, cursor, font_name, font_size) = {
let mut editor = EDITOR.lock().unwrap(); let mut editor = EDITOR.lock();
( (
editor.build_draw_commands(), editor.build_draw_commands(),
editor.default_style.clone(), editor.default_style.clone(),

@ -182,7 +182,7 @@ pub fn ui_loop() {
Event::RedrawRequested { .. } => { Event::RedrawRequested { .. } => {
let frame_start = Instant::now(); let frame_start = Instant::now();
let editor_title = { EDITOR.lock().unwrap().title.clone() }; let editor_title = { EDITOR.lock().title.clone() };
if title != editor_title { if title != editor_title {
title = editor_title; title = editor_title;
window.set_title(&title); window.set_title(&title);

Loading…
Cancel
Save