Skip to content

Commit

Permalink
Merge pull request #610 from gwenn/const_fn
Browse files Browse the repository at this point in the history
Mark some functions as const
  • Loading branch information
gwenn authored Mar 19, 2022
2 parents 7143db0 + 98108e8 commit 4d48e58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn check_bracket(line: &str, pos: usize) -> Option<(u8, usize)> {
}
}

fn matching_bracket(bracket: u8) -> u8 {
const fn matching_bracket(bracket: u8) -> u8 {
match bracket {
b'{' => b'}',
b'}' => b'{',
Expand Down
12 changes: 6 additions & 6 deletions src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub enum Cmd {
impl Cmd {
/// Tells if current command should reset kill ring.
#[must_use]
pub fn should_reset_kill_ring(&self) -> bool {
pub const fn should_reset_kill_ring(&self) -> bool {
#[allow(clippy::match_same_arms)]
match *self {
Cmd::Kill(Movement::BackwardChar(_) | Movement::ForwardChar(_)) => true,
Expand All @@ -144,7 +144,7 @@ impl Cmd {
}
}

fn is_repeatable_change(&self) -> bool {
const fn is_repeatable_change(&self) -> bool {
matches!(
*self,
Cmd::Dedent(..)
Expand All @@ -159,7 +159,7 @@ impl Cmd {
)
}

fn is_repeatable(&self) -> bool {
const fn is_repeatable(&self) -> bool {
match *self {
Cmd::Move(_) => true,
_ => self.is_repeatable_change(),
Expand Down Expand Up @@ -208,7 +208,7 @@ impl Cmd {
}
}

fn repeat_count(previous: RepeatCount, new: Option<RepeatCount>) -> RepeatCount {
const fn repeat_count(previous: RepeatCount, new: Option<RepeatCount>) -> RepeatCount {
match new {
Some(n) => n,
None => previous,
Expand Down Expand Up @@ -260,7 +260,7 @@ pub enum CharSearch {
}

impl CharSearch {
fn opposite(self) -> Self {
const fn opposite(self) -> Self {
match self {
CharSearch::Forward(c) => CharSearch::Backward(c),
CharSearch::ForwardBefore(c) => CharSearch::BackwardAfter(c),
Expand Down Expand Up @@ -306,7 +306,7 @@ pub enum Movement {

impl Movement {
// Replay this movement with a possible different `RepeatCount`.
fn redo(&self, new: Option<RepeatCount>) -> Self {
const fn redo(&self, new: Option<RepeatCount>) -> Self {
match *self {
Movement::WholeLine => Movement::WholeLine,
Movement::BeginningOfLine => Movement::BeginningOfLine,
Expand Down

0 comments on commit 4d48e58

Please sign in to comment.