From 51fafa52cbdc5bff9d3899a4f5595794dffee311 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Thu, 27 Oct 2022 21:33:41 +0800 Subject: [PATCH] remove unnecessary code --- cozorocks/bridge/db.cpp | 12 +------- cozorocks/bridge/db.h | 35 +--------------------- cozorocks/build.rs | 58 ++++++++++++++++++------------------- cozorocks/src/bridge/db.rs | 19 ------------ cozorocks/src/bridge/mod.rs | 4 --- src/data/memcmp.rs | 2 +- src/parse/query.rs | 4 +-- src/runtime/db.rs | 2 +- 8 files changed, 35 insertions(+), 101 deletions(-) diff --git a/cozorocks/bridge/db.cpp b/cozorocks/bridge/db.cpp index 5b811367..fb328d1d 100644 --- a/cozorocks/bridge/db.cpp +++ b/cozorocks/bridge/db.cpp @@ -46,8 +46,7 @@ ColumnFamilyOptions default_cf_options() { return options; } -shared_ptr open_db(const DbOpts &opts, RocksDbStatus &status, bool use_cmp, - RustComparatorFn cmp_impl) { +shared_ptr open_db(const DbOpts &opts, RocksDbStatus &status) { auto options = default_db_options(); if (opts.prepare_for_bulk_load) { @@ -82,20 +81,11 @@ shared_ptr open_db(const DbOpts &opts, RocksDbStatus &status, boo if (opts.use_fixed_prefix_extractor) { options.prefix_extractor.reset(NewFixedPrefixTransform(opts.fixed_prefix_extractor_len)); } - RustComparator *pri_cmp = nullptr; - if (use_cmp) { - pri_cmp = new RustComparator( - string(opts.comparator_name), - opts.comparator_different_bytes_can_be_equal, - cmp_impl); - options.comparator = pri_cmp; - } options.create_missing_column_families = true; shared_ptr db = make_shared(); db->db_path = string(opts.db_path); - db->pri_comparator.reset(pri_cmp); TransactionDB *txn_db = nullptr; write_status( diff --git a/cozorocks/bridge/db.h b/cozorocks/bridge/db.h index b666012f..be20b996 100644 --- a/cozorocks/bridge/db.h +++ b/cozorocks/bridge/db.h @@ -41,7 +41,6 @@ struct SstFileWriterBridge { }; struct RocksDbBridge { - unique_ptr pri_comparator; unique_ptr db; bool destroy_on_exit; @@ -108,39 +107,7 @@ struct RocksDbBridge { ~RocksDbBridge(); }; -//typedef int8_t (*CmpFn)(RustBytes a, RustBytes b); -typedef rust::Fn, rust::Slice)> RustComparatorFn; - -class RustComparator : public Comparator { -public: - inline RustComparator(string name_, bool can_different_bytes_be_equal_, RustComparatorFn f) : - name(std::move(name_)), - ext_cmp(f), - can_different_bytes_be_equal(can_different_bytes_be_equal_) { - } - - [[nodiscard]] inline int Compare(const Slice &a, const Slice &b) const override { - return ext_cmp(convert_slice_back(a), convert_slice_back(b)); - } - - [[nodiscard]] inline const char *Name() const override { - return name.c_str(); - } - - [[nodiscard]] inline bool CanKeysWithDifferentByteContentsBeEqual() const override { - return can_different_bytes_be_equal; - } - - inline void FindShortestSeparator(string *, const Slice &) const override {} - - inline void FindShortSuccessor(string *) const override {} - - string name; - RustComparatorFn ext_cmp; - bool can_different_bytes_be_equal; -}; - shared_ptr -open_db(const DbOpts &opts, RocksDbStatus &status, bool use_cmp, RustComparatorFn cmp_impl); +open_db(const DbOpts &opts, RocksDbStatus &status); #endif //COZOROCKS_DB_H diff --git a/cozorocks/build.rs b/cozorocks/build.rs index c44a8dd8..e475bc56 100644 --- a/cozorocks/build.rs +++ b/cozorocks/build.rs @@ -8,35 +8,6 @@ use std::path::Path; use std::{env, fs, process::Command}; fn main() { - if !Path::new("rocksdb/AUTHORS").exists() { - update_submodules(); - } - - if !try_to_find_and_link_lib("ROCKSDB") { - println!("cargo:rerun-if-changed=rocksdb/"); - fail_on_empty_directory("rocksdb"); - build_rocksdb(); - } else { - let target = env::var("TARGET").unwrap(); - // according to https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L2189 - if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") { - println!("cargo:rustc-link-lib=dylib=c++"); - } else if target.contains("linux") { - println!("cargo:rustc-link-lib=dylib=stdc++"); - } - } - - // Allow dependent crates to locate the sources and output directory of - // this crate. Notably, this allows a dependent crate to locate the RocksDB - // sources and built archive artifacts provided by this crate. - println!( - "cargo:cargo_manifest_dir={}", - env::var("CARGO_MANIFEST_DIR").unwrap() - ); - println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap()); - - - let target = env::var("TARGET").unwrap(); let mut builder = cxx_build::bridge("src/bridge/mod.rs"); @@ -107,6 +78,35 @@ fn main() { println!("cargo:rerun-if-changed=bridge/iter.h"); println!("cargo:rerun-if-changed=bridge/tx.h"); println!("cargo:rerun-if-changed=bridge/tx.cpp"); + + + + if !Path::new("rocksdb/AUTHORS").exists() { + update_submodules(); + } + + if !try_to_find_and_link_lib("ROCKSDB") { + println!("cargo:rerun-if-changed=rocksdb/"); + fail_on_empty_directory("rocksdb"); + build_rocksdb(); + } else { + let target = env::var("TARGET").unwrap(); + // according to https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L2189 + if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") { + println!("cargo:rustc-link-lib=dylib=c++"); + } else if target.contains("linux") { + println!("cargo:rustc-link-lib=dylib=stdc++"); + } + } + + // Allow dependent crates to locate the sources and output directory of + // this crate. Notably, this allows a dependent crate to locate the RocksDB + // sources and built archive artifacts provided by this crate. + println!( + "cargo:cargo_manifest_dir={}", + env::var("CARGO_MANIFEST_DIR").unwrap() + ); + println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap()); } fn link(name: &str, bundled: bool) { diff --git a/cozorocks/src/bridge/db.rs b/cozorocks/src/bridge/db.rs index 0ef2f9c4..c38b20bc 100644 --- a/cozorocks/src/bridge/db.rs +++ b/cozorocks/src/bridge/db.rs @@ -35,8 +35,6 @@ impl<'a> Default for DbOpts<'a> { capped_prefix_extractor_len: 0, use_fixed_prefix_extractor: false, fixed_prefix_extractor_len: 0, - comparator_name: "", - comparator_different_bytes_can_be_equal: false, destroy_on_exit: false, } } @@ -101,29 +99,12 @@ impl<'a> DbBuilder<'a> { self.opts.fixed_prefix_extractor_len = len; self } - pub fn use_custom_comparator( - mut self, - name: &'a str, - cmp: fn(&[u8], &[u8]) -> i8, - different_bytes_can_be_equal: bool, - ) -> Self { - self.cmp_fn = Some(cmp); - self.opts.comparator_name = name; - self.opts.comparator_different_bytes_can_be_equal = different_bytes_can_be_equal; - self - } pub fn build(self) -> Result { let mut status = RocksDbStatus::default(); - fn dummy(_a: &[u8], _b: &[u8]) -> i8 { - 0 - } - let result = open_db( &self.opts, &mut status, - self.cmp_fn.is_some(), - self.cmp_fn.unwrap_or(dummy), ); if status.is_ok() { Ok(RocksDb { inner: result }) diff --git a/cozorocks/src/bridge/mod.rs b/cozorocks/src/bridge/mod.rs index 0fae8bb1..95228ac8 100644 --- a/cozorocks/src/bridge/mod.rs +++ b/cozorocks/src/bridge/mod.rs @@ -34,8 +34,6 @@ pub(crate) mod ffi { pub capped_prefix_extractor_len: usize, pub use_fixed_prefix_extractor: bool, pub fixed_prefix_extractor_len: usize, - pub comparator_name: &'a str, - pub comparator_different_bytes_can_be_equal: bool, pub destroy_on_exit: bool, } @@ -121,8 +119,6 @@ pub(crate) mod ffi { fn open_db( builder: &DbOpts, status: &mut RocksDbStatus, - use_cmp: bool, - cmp_impl: fn(&[u8], &[u8]) -> i8, ) -> SharedPtr; fn transact(self: &RocksDbBridge) -> UniquePtr; fn del_range( diff --git a/src/data/memcmp.rs b/src/data/memcmp.rs index 67cd4d56..2b41c6a9 100644 --- a/src/data/memcmp.rs +++ b/src/data/memcmp.rs @@ -180,7 +180,7 @@ impl Num { n_bytes[6] = subtag[0]; n_bytes[7] = subtag[1]; let n = BigEndian::read_i64(&n_bytes); - return (Num::I(n), remaining); + (Num::I(n), remaining) } } diff --git a/src/parse/query.rs b/src/parse/query.rs index 0dfc2f63..bf5921d3 100644 --- a/src/parse/query.rs +++ b/src/parse/query.rs @@ -199,7 +199,7 @@ pub(crate) fn parse_query( let arity = algo_impl.arity(&options, &head, span)?; ensure!( - arity == 0 || head.len() == 0 || arity == head.len(), + arity == 0 || head.is_empty() || arity == head.len(), FixedRuleHeadArityMismatch(arity, head.len(), span) ); progs.insert( @@ -775,7 +775,7 @@ fn make_empty_const_rule(prog: &mut InputProgram, bindings: &[Symbol]) { }, ); prog.prog.insert( - entry_symbol.clone(), + entry_symbol, InputInlineRulesOrAlgo::Algo { algo: AlgoApply { algo: AlgoHandle { diff --git a/src/runtime/db.rs b/src/runtime/db.rs index 7a811f07..ef29824d 100644 --- a/src/runtime/db.rs +++ b/src/runtime/db.rs @@ -609,7 +609,7 @@ impl Db { } else { Right(sorted_iter) }; - let sorted_iter = sorted_iter.map(|t| Ok(t)); + let sorted_iter = sorted_iter.map(Ok); if let Some((meta, relation_op)) = &input_program.out_opts.store_relation { let to_clear = tx .execute_relation(