Skip to content

Str from bytes API cleanup, attempt 2 #7172

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Next Next commit
std: allow vec::bytes::memcmp to work on slices
  • Loading branch information
erickt committed Jun 19, 2013
commit ad799f200cec632dc57edb0bd39e35c7f69204c0
18 changes: 9 additions & 9 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2413,13 +2413,13 @@ pub mod bytes {
use vec;

/// Bytewise string comparison
pub fn memcmp(a: &~[u8], b: &~[u8]) -> int {
pub fn memcmp(a: &[u8], b: &[u8]) -> int {
let a_len = a.len();
let b_len = b.len();
let n = uint::min(a_len, b_len) as libc::size_t;
let r = unsafe {
libc::memcmp(raw::to_ptr(*a) as *libc::c_void,
raw::to_ptr(*b) as *libc::c_void, n) as int
libc::memcmp(raw::to_ptr(a) as *libc::c_void,
raw::to_ptr(b) as *libc::c_void, n) as int
};

if r != 0 { r } else {
Expand All @@ -2434,22 +2434,22 @@ pub mod bytes {
}

/// Bytewise less than or equal
pub fn lt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) < 0 }
pub fn lt(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) < 0 }

/// Bytewise less than or equal
pub fn le(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) <= 0 }
pub fn le(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) <= 0 }

/// Bytewise equality
pub fn eq(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) == 0 }
pub fn eq(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) == 0 }

/// Bytewise inequality
pub fn ne(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) != 0 }
pub fn ne(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) != 0 }

/// Bytewise greater than or equal
pub fn ge(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) >= 0 }
pub fn ge(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) >= 0 }

/// Bytewise greater than
pub fn gt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) > 0 }
pub fn gt(a: &[u8], b: &[u8]) -> bool { memcmp(a, b) > 0 }

/**
* Copies data from one vector to another.
Expand Down