diff --git a/editor/Cargo.toml b/editor/Cargo.toml index ddefe69e6e..fd0b8f6d6e 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -67,6 +67,7 @@ itertools = "0.9.0" snafu = { version = "0.6", features = ["backtraces"] } colored = "2" + [dependencies.bytemuck] version = "1.4" features = ["derive"] diff --git a/editor/src/buffer.rs b/editor/src/buffer.rs index f6d84866b8..e4b55e0da0 100644 --- a/editor/src/buffer.rs +++ b/editor/src/buffer.rs @@ -3,6 +3,7 @@ use crate::rect::Rect; use crate::util::size_of_slice; use crate::vertex::Vertex; +use bumpalo::collections::Vec as BumpVec; use wgpu::util::{BufferInitDescriptor, DeviceExt}; pub struct QuadBufferBuilder { @@ -87,7 +88,7 @@ pub struct RectBuffers { pub fn create_rect_buffers( gpu_device: &wgpu::Device, encoder: &mut wgpu::CommandEncoder, - rects: &[Rect], + rects: &BumpVec, ) -> RectBuffers { let nr_of_rects = rects.len() as u64; diff --git a/editor/src/lib.rs b/editor/src/lib.rs index ba4956ee74..5ff0e5a137 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -16,6 +16,7 @@ use crate::selection::create_selection_rects; use crate::tea::{model, update}; use crate::text::{build_glyph_brush, is_newline, Text}; use crate::vertex::Vertex; +use bumpalo::Bump; use model::Position; use std::error::Error; use std::io; @@ -121,6 +122,8 @@ fn run_event_loop() -> Result<(), Box> { let mut ed_model = model::init_model(); let mut keyboard_modifiers = ModifiersState::empty(); + let arena = Bump::new(); + // Render loop window.request_redraw(); @@ -216,7 +219,7 @@ fn run_event_loop() -> Result<(), Box> { if let Some(selection) = ed_model.selection_opt { let selection_rects_res = - create_selection_rects(selection, &glyph_bounds_rects); + create_selection_rects(selection, &glyph_bounds_rects, &arena); match selection_rects_res { Ok(selection_rects) => { diff --git a/editor/src/selection.rs b/editor/src/selection.rs index 6a4c77a190..7122ec4673 100644 --- a/editor/src/selection.rs +++ b/editor/src/selection.rs @@ -3,6 +3,8 @@ use crate::error::{EdResult, InvalidSelection}; use crate::rect::Rect; use crate::tea::model::RawSelection; use crate::vec_result::get_res; +use bumpalo::collections::Vec as BumpVec; +use bumpalo::Bump; use snafu::ensure; //using the "parse don't validate" pattern @@ -39,14 +41,15 @@ fn validate_selection(selection: RawSelection) -> EdResult { }) } -pub fn create_selection_rects( +pub fn create_selection_rects<'a>( raw_sel: RawSelection, glyph_bound_rects: &[Vec], -) -> EdResult> { + arena: &'a Bump, +) -> EdResult> { let valid_sel = validate_selection(raw_sel)?; let RawSelection { start_pos, end_pos } = valid_sel.selection; - let mut all_rects = Vec::new(); + let mut all_rects: BumpVec = BumpVec::new_in(arena); if start_pos.line == end_pos.line { let start_glyph_rect = get_res( diff --git a/editor/src/tea/update.rs b/editor/src/tea/update.rs index 48d52abe7a..ff97072ffc 100644 --- a/editor/src/tea/update.rs +++ b/editor/src/tea/update.rs @@ -11,13 +11,13 @@ pub fn move_txt_cursor_left( let old_line_nr = old_txt_cursor_pos.line; let old_col_nr = old_txt_cursor_pos.column; - let (line_nr, col_nr) = if old_txt_cursor_pos.column == 0 { - if old_txt_cursor_pos.line == 0 { + let (line_nr, col_nr) = if old_col_nr == 0 { + if old_line_nr == 0 { (0, 0) } else if let Some(curr_line) = lines.get(old_line_nr - 1) { (old_line_nr - 1, curr_line.len() - 1) } else { - (0, 0) // this should never happen, should this method return Result? + unreachable!() } } else { (old_line_nr, old_col_nr - 1) @@ -84,7 +84,7 @@ pub fn move_txt_cursor_right( (old_line_nr, old_col_nr) } } else { - (0, 0) // this should never happen, should this method return Result? + unreachable!() }; let new_txt_cursor_pos = Position { @@ -140,7 +140,7 @@ pub fn move_txt_cursor_up( (old_line_nr - 1, old_col_nr) } } else { - (0, 0) // this should never happen, should this method return Result? + unreachable!() }; let new_txt_cursor_pos = Position { @@ -195,7 +195,7 @@ pub fn move_txt_cursor_down( (old_line_nr + 1, old_col_nr) } } else { - (0, 0) // this should never happen, should this method return Result? + unreachable!() }; let new_txt_cursor_pos = Position {