mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
chore: fix warnings
This commit is contained in:
parent
ccb2cceea1
commit
f5a21cac8a
3 changed files with 28 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
||||||
use std::borrow::{Borrow, ToOwned};
|
use std::borrow::{Borrow, ToOwned};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::LocalKey;
|
|
||||||
|
|
||||||
use crate::dict::Dict;
|
use crate::dict::Dict;
|
||||||
use crate::set::Set;
|
use crate::set::Set;
|
||||||
|
@ -72,6 +71,30 @@ impl<T: Hash + Eq> CacheSet<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct CacheDict<K, V: ?Sized>(Shared<Dict<K, Arc<V>>>);
|
pub struct CacheDict<K, V: ?Sized>(Shared<Dict<K, Arc<V>>>);
|
||||||
|
|
||||||
pub struct GlobalCacheDict<K: 'static, V: ?Sized + 'static>(LocalKey<Shared<CacheDict<K, V>>>);
|
impl<K: Hash + Eq, V: ?Sized> Default for CacheDict<K, V> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<K: Hash + Eq, V: ?Sized> CacheDict<K, V> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(Shared::new(Dict::new()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<K: Hash + Eq, V> CacheDict<K, V> {
|
||||||
|
pub fn get<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> Option<Arc<V>>
|
||||||
|
where
|
||||||
|
K: Borrow<Q>,
|
||||||
|
{
|
||||||
|
self.0.borrow().get(k).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn insert(&self, k: K, v: V) {
|
||||||
|
self.0.borrow_mut().insert(k, Arc::new(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1611,17 +1611,13 @@ pub mod value_set {
|
||||||
if !is_homogeneous(set) {
|
if !is_homogeneous(set) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
set.iter()
|
set.iter().max_by(|x, y| x.try_cmp(y).unwrap()).cloned()
|
||||||
.max_by(|x, y| x.try_cmp(y).unwrap())
|
|
||||||
.map(Clone::clone)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min(set: &Set<ValueObj>) -> Option<ValueObj> {
|
pub fn min(set: &Set<ValueObj>) -> Option<ValueObj> {
|
||||||
if !is_homogeneous(set) {
|
if !is_homogeneous(set) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
set.iter()
|
set.iter().min_by(|x, y| x.try_cmp(y).unwrap()).cloned()
|
||||||
.min_by(|x, y| x.try_cmp(y).unwrap())
|
|
||||||
.map(Clone::clone)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,9 +1121,7 @@ impl Desugarer {
|
||||||
loc.col_end().unwrap_or(0),
|
loc.col_end().unwrap_or(0),
|
||||||
));
|
));
|
||||||
let name = Expr::from(Identifier::private_from_varname(name));
|
let name = Expr::from(Identifier::private_from_varname(name));
|
||||||
let Some(key) = keys.next() else {
|
let key = keys.next()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
let attr_name = Expr::from(Literal::str(
|
let attr_name = Expr::from(Literal::str(
|
||||||
format!("\"{}\"", key.inspect().clone()),
|
format!("\"{}\"", key.inspect().clone()),
|
||||||
key.ln_begin().unwrap_or(0),
|
key.ln_begin().unwrap_or(0),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue