Skip to content

Commit

Permalink
Add some function inlining (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Nov 27, 2024
1 parent 35226e3 commit 2a9c28e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/reader/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ impl<'a> Coord<'a> {
}
}

#[inline]
fn get_x(&self) -> f64 {
let mut reader = Cursor::new(self.buf);
reader.set_position(self.offset);
reader.read_f64(self.byte_order).unwrap()
}

#[inline]
fn get_y(&self) -> f64 {
let mut reader = Cursor::new(self.buf);
reader.set_position(self.offset + F64_WIDTH);
reader.read_f64(self.byte_order).unwrap()
}

#[inline]
fn get_nth_unchecked(&self, n: usize) -> f64 {
debug_assert!(n < self.dim.size());
let mut reader = Cursor::new(self.buf);
Expand All @@ -84,14 +87,17 @@ impl<'a> CoordTrait for Coord<'a> {
self.dim.into()
}

#[inline]
fn nth_or_panic(&self, n: usize) -> Self::T {
self.get_nth_unchecked(n)
}

#[inline]
fn x(&self) -> Self::T {
self.get_x()
}

#[inline]
fn y(&self) -> Self::T {
self.get_y()
}
Expand Down
3 changes: 3 additions & 0 deletions src/reader/linearring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl<'a> WKBLinearRing<'a> {
}

/// The offset into this buffer of any given coordinate
#[inline]
pub fn coord_offset(&self, i: u64) -> u64 {
self.offset + 4 + (self.dim.size() as u64 * 8 * i)
}
Expand All @@ -72,10 +73,12 @@ impl<'a> LineStringTrait for WKBLinearRing<'a> {
self.dim.into()
}

#[inline]
fn num_coords(&self) -> usize {
self.num_points
}

#[inline]
unsafe fn coord_unchecked(&self, i: usize) -> Self::CoordType<'_> {
Coord::new(
self.buf,
Expand Down
4 changes: 0 additions & 4 deletions src/reader/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ impl<'a> Polygon<'a> {
.fold(1 + 4 + 4, |acc, ring| acc + ring.size())
}

pub fn is_empty(&self) -> bool {
self.wkb_linear_rings.len() == 0
}

pub fn dimension(&self) -> WKBDimension {
self.dim
}
Expand Down

0 comments on commit 2a9c28e

Please sign in to comment.