Skip to content

Commit

Permalink
fix: optimize bytes.has_prefix()
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhbx-smartosc committed Apr 16, 2024
1 parent 81148e0 commit 3ed7664
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cardano/lib/ibc/utils/bytes.ak
@@ -1,7 +1,7 @@
use aiken/builtin.{
add_integer as add, divide_integer as div, if_then_else as ite,
}
use aiken/bytearray.{compare, length, push, slice}
use aiken/bytearray.{push}
use ibc/utils/bits.{len64}
use ibc/utils/int.{Int64}

Expand Down Expand Up @@ -39,9 +39,7 @@ pub fn read_varint(r: ByteArray, pos: Int) -> (Int, Int) {
}

pub fn has_prefix(s: ByteArray, prefix: ByteArray) -> Bool {
let p_length = length(prefix)
expect length(s) >= p_length
compare(slice(s, 0, p_length - 1), prefix) == Equal
bytearray.take(s, bytearray.length(prefix)) == prefix
}

pub fn encode_varint(v: Int64) -> ByteArray {
Expand Down

0 comments on commit 3ed7664

Please sign in to comment.