Replace unnecessary exchange util.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -5,11 +5,10 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
|
mem::replace,
|
||||||
sync::{Mutex, OnceLock},
|
sync::{Mutex, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::exchange;
|
|
||||||
|
|
||||||
// Capture rustc version during compilation.
|
// Capture rustc version during compilation.
|
||||||
tuwunel_macros::rustc_version! {}
|
tuwunel_macros::rustc_version! {}
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ fn append_features(features: &mut Vec<&'static str>, flags: &[&'static str]) {
|
|||||||
for flag in flags {
|
for flag in flags {
|
||||||
let is_cfg = *flag == "--cfg";
|
let is_cfg = *flag == "--cfg";
|
||||||
let is_feature = flag.starts_with("feature=");
|
let is_feature = flag.starts_with("feature=");
|
||||||
if exchange(&mut next_is_cfg, is_cfg) && is_feature {
|
if replace(&mut next_is_cfg, is_cfg) && is_feature {
|
||||||
if let Some(feature) = flag
|
if let Some(feature) = flag
|
||||||
.split_once('=')
|
.split_once('=')
|
||||||
.map(|(_, feature)| feature.trim_matches('"'))
|
.map(|(_, feature)| feature.trim_matches('"'))
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ pub use self::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn exchange<T>(state: &mut T, source: T) -> T { std::mem::replace(state, source) }
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! extract_variant {
|
macro_rules! extract_variant {
|
||||||
( $e:expr_2021, $( $variant:path )|* ) => {
|
( $e:expr_2021, $( $variant:path )|* ) => {
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ mod tests;
|
|||||||
mod unquote;
|
mod unquote;
|
||||||
mod unquoted;
|
mod unquoted;
|
||||||
|
|
||||||
|
use std::mem::replace;
|
||||||
|
|
||||||
pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::Unquoted};
|
pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::Unquoted};
|
||||||
use crate::{Result, smallstr::SmallString, utils::exchange};
|
use crate::{Result, smallstr::SmallString};
|
||||||
|
|
||||||
pub const EMPTY: &str = "";
|
pub const EMPTY: &str = "";
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ where
|
|||||||
.map(char::from)
|
.map(char::from)
|
||||||
.try_for_each(|ch| {
|
.try_for_each(|ch| {
|
||||||
let m = ch.is_ascii_uppercase();
|
let m = ch.is_ascii_uppercase();
|
||||||
let s = exchange(&mut state, !m);
|
let s = replace(&mut state, !m);
|
||||||
if m && s {
|
if m && s {
|
||||||
output.write_char('_')?;
|
output.write_char('_')?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::io::Write;
|
use std::{io::Write, mem::replace};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize, ser};
|
use serde::{Deserialize, Serialize, ser};
|
||||||
use tuwunel_core::{Error, Result, debug::type_name, err, result::DebugInspect, utils::exchange};
|
use tuwunel_core::{Error, Result, debug::type_name, err, result::DebugInspect};
|
||||||
|
|
||||||
use crate::util::unhandled;
|
use crate::util::unhandled;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ impl<W: Write> Serializer<'_, W> {
|
|||||||
|
|
||||||
fn record_start(&mut self) -> Result {
|
fn record_start(&mut self) -> Result {
|
||||||
debug_assert!(!self.is_finalized(), "Starting a record after serialization finalized");
|
debug_assert!(!self.is_finalized(), "Starting a record after serialization finalized");
|
||||||
exchange(&mut self.sep, true)
|
replace(&mut self.sep, true)
|
||||||
.then(|| self.separator())
|
.then(|| self.separator())
|
||||||
.unwrap_or(Ok(()))
|
.unwrap_or(Ok(()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ mod items_rev;
|
|||||||
mod keys;
|
mod keys;
|
||||||
mod keys_rev;
|
mod keys_rev;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{mem::replace, sync::Arc};
|
||||||
|
|
||||||
use rocksdb::{DBRawIteratorWithThreadMode, ReadOptions};
|
use rocksdb::{DBRawIteratorWithThreadMode, ReadOptions};
|
||||||
use tuwunel_core::{Result, utils::exchange};
|
use tuwunel_core::Result;
|
||||||
|
|
||||||
pub(crate) use self::{items::Items, items_rev::ItemsRev, keys::Keys, keys_rev::KeysRev};
|
pub(crate) use self::{items::Items, items_rev::ItemsRev, keys::Keys, keys_rev::KeysRev};
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -94,7 +94,7 @@ impl<'a> State<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(unabridged, tracing::instrument(level = "trace", skip_all))]
|
#[cfg_attr(unabridged, tracing::instrument(level = "trace", skip_all))]
|
||||||
pub(super) fn seek_fwd(&mut self) {
|
pub(super) fn seek_fwd(&mut self) {
|
||||||
if !exchange(&mut self.init, false) {
|
if !replace(&mut self.init, false) {
|
||||||
self.inner.next();
|
self.inner.next();
|
||||||
} else if !self.seek {
|
} else if !self.seek {
|
||||||
self.inner.seek_to_first();
|
self.inner.seek_to_first();
|
||||||
@@ -104,7 +104,7 @@ impl<'a> State<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(unabridged, tracing::instrument(level = "trace", skip_all))]
|
#[cfg_attr(unabridged, tracing::instrument(level = "trace", skip_all))]
|
||||||
pub(super) fn seek_rev(&mut self) {
|
pub(super) fn seek_rev(&mut self) {
|
||||||
if !exchange(&mut self.init, false) {
|
if !replace(&mut self.init, false) {
|
||||||
self.inner.prev();
|
self.inner.prev();
|
||||||
} else if !self.seek {
|
} else if !self.seek {
|
||||||
self.inner.seek_to_last();
|
self.inner.seek_to_last();
|
||||||
|
|||||||
Reference in New Issue
Block a user