Merge pull request #266 from aleksuss/clippy-lints

Applied clippy lints
master
Oleksandr Anyshchenko 6 years ago committed by GitHub
commit 1038c71df8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      librocksdb-sys/rocksdb_lib_sources.txt
  2. 17
      src/db.rs
  3. 4
      src/db_options.rs
  4. 2
      src/lib.rs
  5. 21
      src/merge_operator.rs
  6. 6
      src/slice_transform.rs
  7. 5
      tests/test_column_family.rs
  8. 2
      tests/test_db.rs
  9. 4
      tests/test_iterator.rs
  10. 4
      tests/test_slice_transform.rs

File diff suppressed because one or more lines are too long

@ -554,7 +554,7 @@ impl<'a> Snapshot<'a> {
pub fn new(db: &DB) -> Snapshot { pub fn new(db: &DB) -> Snapshot {
let snapshot = unsafe { ffi::rocksdb_create_snapshot(db.inner) }; let snapshot = unsafe { ffi::rocksdb_create_snapshot(db.inner) };
Snapshot { Snapshot {
db: db, db,
inner: snapshot, inner: snapshot,
} }
} }
@ -726,7 +726,7 @@ impl DB {
let db: *mut ffi::rocksdb_t; let db: *mut ffi::rocksdb_t;
let cf_map = Arc::new(RwLock::new(BTreeMap::new())); let cf_map = Arc::new(RwLock::new(BTreeMap::new()));
if cfs.len() == 0 { if cfs.is_empty() {
unsafe { unsafe {
db = ffi_try!(ffi::rocksdb_open(opts.inner, cpath.as_ptr() as *const _,)); db = ffi_try!(ffi::rocksdb_open(opts.inner, cpath.as_ptr() as *const _,));
} }
@ -1366,7 +1366,7 @@ impl DB {
pub fn set_options(&self, opts: &[(&str, &str)]) -> Result<(), Error> { pub fn set_options(&self, opts: &[(&str, &str)]) -> Result<(), Error> {
let copts = opts let copts = opts
.into_iter() .iter()
.map(|(name, value)| { .map(|(name, value)| {
let cname = match CString::new(name.as_bytes()) { let cname = match CString::new(name.as_bytes()) {
Ok(cname) => cname, Ok(cname) => cname,
@ -1383,14 +1383,15 @@ impl DB {
let cnames: Vec<*const c_char> = copts.iter().map(|opt| opt.0.as_ptr()).collect(); let cnames: Vec<*const c_char> = copts.iter().map(|opt| opt.0.as_ptr()).collect();
let cvalues: Vec<*const c_char> = copts.iter().map(|opt| opt.1.as_ptr()).collect(); let cvalues: Vec<*const c_char> = copts.iter().map(|opt| opt.1.as_ptr()).collect();
let count = opts.len() as i32; let count = opts.len() as i32;
Ok(unsafe { unsafe {
ffi_try!(ffi::rocksdb_set_options( ffi_try!(ffi::rocksdb_set_options(
self.inner, self.inner,
count, count,
cnames.as_ptr(), cnames.as_ptr(),
cvalues.as_ptr(), cvalues.as_ptr(),
)) ));
}) }
Ok(())
} }
/// Retrieves a RocksDB property by name. /// Retrieves a RocksDB property by name.
@ -1869,7 +1870,7 @@ impl<'a> DBPinnableSlice<'a> {
fn test_db_vector() { fn test_db_vector() {
use std::mem; use std::mem;
let len: size_t = 4; let len: size_t = 4;
let data: *mut u8 = unsafe { mem::transmute(libc::calloc(len, mem::size_of::<u8>())) }; let data = unsafe { libc::calloc(len, mem::size_of::<u8>()) as *mut u8 };
let v = unsafe { DBVector::from_c(data, len) }; let v = unsafe { DBVector::from_c(data, len) };
let ctrl = [0u8, 0, 0, 0]; let ctrl = [0u8, 0, 0, 0];
assert_eq!(&*v, &ctrl[..]); assert_eq!(&*v, &ctrl[..]);
@ -1919,7 +1920,7 @@ fn writebatch_works() {
{ {
let db = DB::open_default(path).unwrap(); let db = DB::open_default(path).unwrap();
{ {
// test put // test putx
let mut batch = WriteBatch::default(); let mut batch = WriteBatch::default();
assert!(db.get(b"k1").unwrap().is_none()); assert!(db.get(b"k1").unwrap().is_none());
assert_eq!(batch.len(), 0); assert_eq!(batch.len(), 0);

@ -277,7 +277,7 @@ impl Options {
) { ) {
let cb = Box::new(MergeOperatorCallback { let cb = Box::new(MergeOperatorCallback {
name: CString::new(name.as_bytes()).unwrap(), name: CString::new(name.as_bytes()).unwrap(),
full_merge_fn: full_merge_fn, full_merge_fn,
partial_merge_fn: partial_merge_fn.unwrap_or(full_merge_fn), partial_merge_fn: partial_merge_fn.unwrap_or(full_merge_fn),
}); });
@ -318,7 +318,7 @@ impl Options {
{ {
let cb = Box::new(CompactionFilterCallback { let cb = Box::new(CompactionFilterCallback {
name: CString::new(name.as_bytes()).unwrap(), name: CString::new(name.as_bytes()).unwrap(),
filter_fn: filter_fn, filter_fn,
}); });
unsafe { unsafe {

@ -114,7 +114,7 @@ impl Error {
Error { message } Error { message }
} }
pub fn to_string(self) -> String { pub fn into_string(self) -> String {
self.into() self.into()
} }
} }

@ -94,7 +94,7 @@ pub unsafe extern "C" fn full_merge_callback(
let cb = &mut *(raw_cb as *mut MergeOperatorCallback); let cb = &mut *(raw_cb as *mut MergeOperatorCallback);
let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands); let operands = &mut MergeOperands::new(operands_list, operands_list_len, num_operands);
let key = slice::from_raw_parts(raw_key as *const u8, key_len as usize); let key = slice::from_raw_parts(raw_key as *const u8, key_len as usize);
let oldval = if existing_value == ptr::null() { let oldval = if existing_value.is_null() {
None None
} else { } else {
Some(slice::from_raw_parts( Some(slice::from_raw_parts(
@ -160,8 +160,8 @@ impl MergeOperands {
) -> MergeOperands { ) -> MergeOperands {
assert!(num_operands >= 0); assert!(num_operands >= 0);
MergeOperands { MergeOperands {
operands_list: operands_list, operands_list,
operands_list_len: operands_list_len, operands_list_len,
num_operands: num_operands as usize, num_operands: num_operands as usize,
cursor: 0, cursor: 0,
} }
@ -273,12 +273,12 @@ mod test {
); );
None None
} else { } else {
unsafe { Some(::std::mem::transmute(s.as_ptr())) } unsafe { Some(&*(s.as_ptr() as *const T)) }
} }
} }
#[repr(packed)] #[repr(packed)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, Default)]
struct ValueCounts { struct ValueCounts {
num_a: u32, num_a: u32,
num_b: u32, num_b: u32,
@ -306,15 +306,10 @@ mod test {
existing_val: Option<&[u8]>, existing_val: Option<&[u8]>,
operands: &mut MergeOperands, operands: &mut MergeOperands,
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
let mut counts: ValueCounts = if let Some(v) = existing_val { let mut counts = if let Some(v) = existing_val {
from_slice::<ValueCounts>(v).unwrap().clone() *from_slice::<ValueCounts>(v).unwrap_or(&ValueCounts::default())
} else { } else {
ValueCounts { ValueCounts::default()
num_a: 0,
num_b: 0,
num_c: 0,
num_d: 0,
}
}; };
for op in operands { for op in operands {

@ -43,8 +43,8 @@ impl SliceTransform {
) -> SliceTransform { ) -> SliceTransform {
let cb = Box::new(TransformCallback { let cb = Box::new(TransformCallback {
name: CString::new(name.as_bytes()).unwrap(), name: CString::new(name.as_bytes()).unwrap(),
transform_fn: transform_fn, transform_fn,
in_domain_fn: in_domain_fn, in_domain_fn,
}); });
let st = unsafe { let st = unsafe {
@ -55,7 +55,7 @@ impl SliceTransform {
// this is ugly, but I can't get the compiler // this is ugly, but I can't get the compiler
// not to barf with "expected fn pointer, found fn item" // not to barf with "expected fn pointer, found fn item"
// without this. sorry. // without this. sorry.
if let Some(_) = in_domain_fn { if in_domain_fn.is_some() {
Some(in_domain_callback) Some(in_domain_callback)
} else { } else {
None None

@ -179,14 +179,11 @@ fn test_provided_merge(
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
let nops = operands.size_hint().0; let nops = operands.size_hint().0;
let mut result: Vec<u8> = Vec::with_capacity(nops); let mut result: Vec<u8> = Vec::with_capacity(nops);
match existing_val { if let Some(v) = existing_val {
Some(v) => {
for e in v { for e in v {
result.push(*e); result.push(*e);
} }
} }
None => (),
}
for op in operands { for op in operands {
for e in op { for e in op {
result.push(*e); result.push(*e);

@ -26,7 +26,7 @@ use util::DBPath;
fn test_db_vector() { fn test_db_vector() {
use std::mem; use std::mem;
let len: size_t = 4; let len: size_t = 4;
let data: *mut u8 = unsafe { mem::transmute(libc::calloc(len, mem::size_of::<u8>())) }; let data: *mut u8 = unsafe { libc::calloc(len, mem::size_of::<u8>()) as *mut u8 };
let v = unsafe { DBVector::from_c(data, len) }; let v = unsafe { DBVector::from_c(data, len) };
let ctrl = [0u8, 0, 0, 0]; let ctrl = [0u8, 0, 0, 0];
assert_eq!(&*v, &ctrl[..]); assert_eq!(&*v, &ctrl[..]);

@ -18,8 +18,8 @@ mod util;
use rocksdb::{Direction, IteratorMode, MemtableFactory, Options, DB}; use rocksdb::{Direction, IteratorMode, MemtableFactory, Options, DB};
use util::DBPath; use util::DBPath;
fn cba(input: &Box<[u8]>) -> Box<[u8]> { fn cba(input: &[u8]) -> Box<[u8]> {
input.iter().cloned().collect::<Vec<_>>().into_boxed_slice() input.to_vec().into_boxed_slice()
} }
#[test] #[test]

@ -30,8 +30,8 @@ pub fn test_slice_transform() {
assert!(db.put(&*b1, &*b1).is_ok()); assert!(db.put(&*b1, &*b1).is_ok());
assert!(db.put(&*b2, &*b2).is_ok()); assert!(db.put(&*b2, &*b2).is_ok());
fn cba(input: &Box<[u8]>) -> Box<[u8]> { fn cba(input: &[u8]) -> Box<[u8]> {
input.iter().cloned().collect::<Vec<_>>().into_boxed_slice() input.to_vec().into_boxed_slice()
} }
fn key(k: &[u8]) -> Box<[u8]> { fn key(k: &[u8]) -> Box<[u8]> {

Loading…
Cancel
Save