Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some function inlining #38

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading