Skip to content

Commit

Permalink
*: refactor: remove the tikv_util::map macro (tikv#10886)
Browse files Browse the repository at this point in the history
* *: refactor: remove the tikv_util::map macro

Signed-off-by: kennytm <[email protected]>

* raftstore: fix clippy

Signed-off-by: kennytm <[email protected]>
  • Loading branch information
kennytm authored Sep 3, 2021
1 parent 62dd35c commit b9426ea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 93 deletions.
9 changes: 4 additions & 5 deletions components/raftstore/src/store/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use file_system::{
use keys::{enc_end_key, enc_start_key};
use tikv_util::time::{duration_to_sec, Instant, Limiter};
use tikv_util::HandyRwLock;
use tikv_util::{box_err, box_try, debug, error, info, map, warn};
use tikv_util::{box_err, box_try, debug, error, info, warn};

use crate::coprocessor::CoprocessorHost;
use crate::store::metrics::{
Expand Down Expand Up @@ -1515,7 +1515,7 @@ impl SnapManagerBuilder {
SnapManager {
core: SnapManagerCore {
base: path.into(),
registry: Arc::new(RwLock::new(map![])),
registry: Default::default(),
limiter,
temp_sst_id: Arc::new(AtomicU64::new(0)),
encryption_key_manager: self.key_manager,
Expand All @@ -1532,7 +1532,7 @@ pub mod tests {
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, AtomicUsize};
use std::sync::{Arc, RwLock};
use std::sync::Arc;

use encryption::{EncryptionConfig, FileConfig, MasterKeyConfig};
use encryption_export::data_key_manager_from_config;
Expand All @@ -1553,7 +1553,6 @@ pub mod tests {

use protobuf::Message;
use tempfile::{Builder, TempDir};
use tikv_util::map;
use tikv_util::time::Limiter;

use super::{
Expand Down Expand Up @@ -1699,7 +1698,7 @@ pub mod tests {
fn create_manager_core(path: &str) -> SnapManagerCore {
SnapManagerCore {
base: path.to_owned(),
registry: Arc::new(RwLock::new(map![])),
registry: Default::default(),
limiter: Limiter::new(f64::INFINITY),
temp_sst_id: Arc::new(AtomicU64::new(0)),
encryption_key_manager: None,
Expand Down
35 changes: 18 additions & 17 deletions components/tidb_query_datatype/src/codec/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,12 @@ pub fn generate_index_data_for_test(

#[cfg(test)]
mod tests {
use std::i64;
use std::{i64, iter::FromIterator};

use tipb::ColumnInfo;

use crate::codec::datum::{self, Datum};
use collections::{HashMap, HashSet};
use tikv_util::map;

use super::*;

Expand Down Expand Up @@ -623,21 +622,23 @@ mod tests {
.set_tp(FieldTypeTp::Duration)
.set_decimal(2);

let mut cols = map![
1 => FieldTypeTp::LongLong.into(),
2 => FieldTypeTp::VarChar.into(),
3 => FieldTypeTp::NewDecimal.into(),
5 => FieldTypeTp::JSON.into(),
6 => duration_col
];

let mut row = map![
1 => Datum::I64(100),
2 => Datum::Bytes(b"abc".to_vec()),
3 => Datum::Dec(10.into()),
5 => Datum::Json(r#"{"name": "John"}"#.parse().unwrap()),
6 => Datum::Dur(Duration::parse(&mut EvalContext::default(),"23:23:23.666",2 ).unwrap())
];
let mut cols = HashMap::from_iter([
(1, FieldTypeTp::LongLong.into()),
(2, FieldTypeTp::VarChar.into()),
(3, FieldTypeTp::NewDecimal.into()),
(5, FieldTypeTp::JSON.into()),
(6, duration_col),
]);

let duration_row = Duration::parse(&mut EvalContext::default(), "23:23:23.666", 2).unwrap();

let mut row = HashMap::from_iter([
(1, Datum::I64(100)),
(2, Datum::Bytes(b"abc".to_vec())),
(3, Datum::Dec(10.into())),
(5, Datum::Json(r#"{"name": "John"}"#.parse().unwrap())),
(6, Datum::Dur(duration_row)),
]);

let mut ctx = EvalContext::default();
let col_ids: Vec<_> = row.iter().map(|(&id, _)| id).collect();
Expand Down
64 changes: 0 additions & 64 deletions components/tikv_util/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,6 @@

//! The macros crate contains all useful needed macros.
/// Gets the count of macro's arguments.
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate tikv_util;
/// # fn main() {
/// assert_eq!(count_args!(), 0);
/// assert_eq!(count_args!(1), 1);
/// assert_eq!(count_args!(1, 2), 2);
/// assert_eq!(count_args!(1, 2, 3), 3);
/// # }
/// ```
#[macro_export]
macro_rules! count_args {
() => { 0 };
($head:expr $(, $tail:expr)*) => { 1 + $crate::count_args!($($tail),*) };
}

/// Initializes a `HashMap` with specified key-value pairs.
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate tikv_util;
/// # fn main() {
/// // empty map
/// let m: tikv_util::collections::HashMap<u8, u8> = map!();
/// assert!(m.is_empty());
///
/// // one initial kv pairs.
/// let m = map!("key" => "value");
/// assert_eq!(m.len(), 1);
/// assert_eq!(m["key"], "value");
///
/// // initialize with multiple kv pairs.
/// let m = map!("key1" => "value1", "key2" => "value2");
/// assert_eq!(m.len(), 2);
/// assert_eq!(m["key1"], "value1");
/// assert_eq!(m["key2"], "value2");
/// # }
/// ```
#[macro_export]
macro_rules! map {
() => {
{
collections::HashMap::default()
}
};
( $( $k:expr => $v:expr ),+ ) => {
{
let mut temp_map =
collections::HashMap::with_capacity_and_hasher(
$crate::count_args!($(($k, $v)),+),
Default::default()
);
$(
temp_map.insert($k, $v);
)+
temp_map
}
};
}

/// A shortcut to box an error.
#[macro_export]
macro_rules! box_err {
Expand Down
10 changes: 5 additions & 5 deletions src/storage/txn/flow_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ impl<E: KvEngine> FlowChecker<E> {
discard_ratio: Arc<AtomicU32>,
limiter: Arc<Limiter>,
) -> Self {
let mut cf_checkers = map![];

for cf in engine.cf_names() {
cf_checkers.insert(cf.to_owned(), CFFlowChecker::default());
}
let cf_checkers = engine
.cf_names()
.into_iter()
.map(|cf| (cf.to_owned(), CFFlowChecker::default()))
.collect();

Self {
soft_pending_compaction_bytes_limit: config.soft_pending_compaction_bytes_limit.0,
Expand Down
5 changes: 3 additions & 2 deletions tests/integrations/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

use std::fs::File;
use std::io::Read;
use std::iter::FromIterator;
use std::path::PathBuf;

use slog::Level;

use batch_system::Config as BatchSystemConfig;
use collections::HashSet;
use collections::{HashMap, HashSet};
use encryption::{EncryptionConfig, FileConfig, MasterKeyConfig};
use engine_rocks::config::{BlobRunMode, CompressionType, LogLevel};
use engine_rocks::raw::{
Expand Down Expand Up @@ -68,7 +69,7 @@ fn test_serde_custom_tikv_config() {
value.server = ServerConfig {
cluster_id: 0, // KEEP IT ZERO, it is skipped by serde.
addr: "example.com:443".to_owned(),
labels: map! { "a".to_owned() => "b".to_owned() },
labels: HashMap::from_iter([("a".to_owned(), "b".to_owned())]),
advertise_addr: "example.com:443".to_owned(),
status_addr: "example.com:443".to_owned(),
advertise_status_addr: "example.com:443".to_owned(),
Expand Down

0 comments on commit b9426ea

Please sign in to comment.