Skip to content

Commit

Permalink
feature(core): mark some internal functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindln committed Oct 7, 2020
1 parent 6ef5b08 commit 28514ec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions miniz_oxide/src/deflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn write_u16_le(val: u16, slice: &mut [u8], pos: usize) {

// Read the two bytes starting at pos and interpret them as an u16.
#[inline]
fn read_u16_le(slice: &[u8], pos: usize) -> u16 {
const fn read_u16_le(slice: &[u8], pos: usize) -> u16 {
// The compiler is smart enough to optimize this into an unaligned load.
slice[pos] as u16 | ((slice[pos + 1] as u16) << 8)
}
Expand Down Expand Up @@ -675,7 +675,7 @@ impl<'a> OutputBufferOxide<'a> {
}
}

fn save(&self) -> SavedOutputBufferOxide {
const fn save(&self) -> SavedOutputBufferOxide {
SavedOutputBufferOxide {
pos: self.inner_pos,
bit_buffer: self.bit_buffer,
Expand Down Expand Up @@ -1184,7 +1184,7 @@ struct DictOxide {
pub size: usize,
}

fn probes_from_flags(flags: u32) -> [u32; 2] {
const fn probes_from_flags(flags: u32) -> [u32; 2] {
[
1 + ((flags & 0xFFF) + 2) / 3,
1 + (((flags & 0xFFF) >> 2) + 2) / 3,
Expand Down Expand Up @@ -1446,7 +1446,7 @@ struct LZOxide {
}

impl LZOxide {
fn new() -> Self {
const fn new() -> Self {
LZOxide {
codes: [0; LZ_CODE_BUF_SIZE],
code_position: 1,
Expand Down
2 changes: 1 addition & 1 deletion miniz_oxide/src/inflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct HuffmanTable {
}

impl HuffmanTable {
fn new() -> HuffmanTable {
const fn new() -> HuffmanTable {
HuffmanTable {
code_size: [0; MAX_HUFF_SYMBOLS_0],
look_up: [0; FAST_LOOKUP_SIZE as usize],
Expand Down
6 changes: 3 additions & 3 deletions miniz_oxide/src/inflate/output_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<'a> OutputBuffer<'a> {
}

#[inline]
pub fn position(&self) -> usize {
pub const fn position(&self) -> usize {
self.position
}

Expand Down Expand Up @@ -44,12 +44,12 @@ impl<'a> OutputBuffer<'a> {
}

#[inline]
pub fn bytes_left(&self) -> usize {
pub const fn bytes_left(&self) -> usize {
self.slice.len() - self.position
}

#[inline]
pub fn get_ref(&self) -> &[u8] {
pub const fn get_ref(&self) -> &[u8] {
self.slice
}

Expand Down
2 changes: 1 addition & 1 deletion miniz_oxide/src/inflate/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl InflateState {
}

/// Return the status of the last call to `inflate` with this `InflateState`.
pub fn last_status(&self) -> TINFLStatus {
pub const fn last_status(&self) -> TINFLStatus {
self.last_status
}

Expand Down

0 comments on commit 28514ec

Please sign in to comment.