Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cac433

Browse files
authored
Constify functions & General nitpicks (#5858)
* General cleanups* Add some newlines* Use bitlag match* More constify* Don't convert to str twice* constify more* Use match directly instead of if & match!* Constify more* Constify more* more consts* Constify more* Constify more* Don't use bitflags_match macro
1 parente41d7f5 commit8cac433

39 files changed

+273
-141
lines changed

‎common/src/borrow.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl<'a, T: ?Sized> BorrowedValue<'a, T> {
5656

5757
impl<T: ?Sized>DerefforBorrowedValue<'_,T>{
5858
typeTarget =T;
59+
5960
fnderef(&self) ->&T{
6061
matchself{
6162
Self::Ref(r) => r,
@@ -81,6 +82,7 @@ pub enum BorrowedValueMut<'a, T: ?Sized> {
8182
WriteLock(PyRwLockWriteGuard<'a,T>),
8283
MappedWriteLock(PyMappedRwLockWriteGuard<'a,T>),
8384
}
85+
8486
impl_from!('a,T,BorrowedValueMut<'a,T>,
8587
RefMut(&'amutT),
8688
MuLock(PyMutexGuard<'a,T>),
@@ -108,6 +110,7 @@ impl<'a, T: ?Sized> BorrowedValueMut<'a, T> {
108110

109111
impl<T: ?Sized>DerefforBorrowedValueMut<'_,T>{
110112
typeTarget =T;
113+
111114
fnderef(&self) ->&T{
112115
matchself{
113116
Self::RefMut(r) => r,

‎common/src/boxvec.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ impl<T> BoxVec<T> {
4646
}
4747

4848
#[inline]
49-
pubfnlen(&self) ->usize{
49+
pubconstfnlen(&self) ->usize{
5050
self.len
5151
}
5252

5353
#[inline]
54-
pubfnis_empty(&self) ->bool{
54+
pubconstfnis_empty(&self) ->bool{
5555
self.len() ==0
5656
}
5757

5858
#[inline]
59-
pubfncapacity(&self) ->usize{
59+
pubconstfncapacity(&self) ->usize{
6060
self.xs.len()
6161
}
6262

63-
pubfnis_full(&self) ->bool{
63+
pubconstfnis_full(&self) ->bool{
6464
self.len() ==self.capacity()
6565
}
6666

67-
pubfnremaining_capacity(&self) ->usize{
67+
pubconstfnremaining_capacity(&self) ->usize{
6868
self.capacity() -self.len()
6969
}
7070

@@ -336,6 +336,7 @@ impl<T> BoxVec<T> {
336336

337337
impl<T>DerefforBoxVec<T>{
338338
typeTarget =[T];
339+
339340
#[inline]
340341
fnderef(&self) ->&[T]{
341342
unsafe{ slice::from_raw_parts(self.as_ptr(),self.len())}
@@ -354,6 +355,7 @@ impl<T> DerefMut for BoxVec<T> {
354355
impl<'a,T>IntoIteratorfor&'aBoxVec<T>{
355356
typeItem =&'aT;
356357
typeIntoIter = slice::Iter<'a,T>;
358+
357359
fninto_iter(self) ->Self::IntoIter{
358360
self.iter()
359361
}
@@ -363,6 +365,7 @@ impl<'a, T> IntoIterator for &'a BoxVec<T> {
363365
impl<'a,T>IntoIteratorfor&'amutBoxVec<T>{
364366
typeItem =&'amutT;
365367
typeIntoIter = slice::IterMut<'a,T>;
368+
366369
fninto_iter(self) ->Self::IntoIter{
367370
self.iter_mut()
368371
}
@@ -374,6 +377,7 @@ impl<'a, T> IntoIterator for &'a mut BoxVec<T> {
374377
impl<T>IntoIteratorforBoxVec<T>{
375378
typeItem =T;
376379
typeIntoIter =IntoIter<T>;
380+
377381
fninto_iter(self) ->IntoIter<T>{
378382
IntoIter{index:0,v:self}
379383
}
@@ -672,7 +676,7 @@ pub struct CapacityError<T = ()> {
672676

673677
impl<T>CapacityError<T>{
674678
/// Create a new `CapacityError` from `element`.
675-
pubfnnew(element:T) ->CapacityError<T>{
679+
pubconstfnnew(element:T) ->CapacityError<T>{
676680
CapacityError{ element}
677681
}
678682

‎common/src/cformat.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ pub enum CFloatType {
7676
}
7777

7878
implCFloatType{
79-
fncase(self) ->Case{
79+
constfncase(self) ->Case{
8080
useCFloatType::*;
81+
8182
matchself{
8283
ExponentLower |PointDecimalLower |GeneralLower =>Case::Lower,
8384
ExponentUpper |PointDecimalUpper |GeneralUpper =>Case::Upper,
@@ -100,7 +101,7 @@ pub enum CFormatType {
100101
}
101102

102103
implCFormatType{
103-
pubfnto_char(self) ->char{
104+
pubconstfnto_char(self) ->char{
104105
matchself{
105106
CFormatType::Number(x) => xasu8aschar,
106107
CFormatType::Float(x) => xasu8aschar,
@@ -136,9 +137,9 @@ bitflags! {
136137
implCConversionFlags{
137138
#[inline]
138139
pubfnsign_string(&self) ->&'staticstr{
139-
ifself.contains(CConversionFlags::SIGN_CHAR){
140+
ifself.contains(Self::SIGN_CHAR){
140141
"+"
141-
}elseifself.contains(CConversionFlags::BLANK_SIGN){
142+
}elseifself.contains(Self::BLANK_SIGN){
142143
" "
143144
}else{
144145
""
@@ -171,12 +172,15 @@ pub trait FormatChar: Copy + Into<CodePoint> + From<u8> {
171172

172173
implFormatBufforString{
173174
typeChar =char;
175+
174176
fnchars(&self) ->implIterator<Item =Self::Char>{
175177
(**self).chars()
176178
}
179+
177180
fnlen(&self) ->usize{
178181
self.len()
179182
}
183+
180184
fnconcat(mutself,other:Self) ->Self{
181185
self.extend([other]);
182186
self
@@ -187,19 +191,23 @@ impl FormatChar for char {
187191
fnto_char_lossy(self) ->char{
188192
self
189193
}
194+
190195
fneq_char(self,c:char) ->bool{
191196
self == c
192197
}
193198
}
194199

195200
implFormatBufforWtf8Buf{
196201
typeChar =CodePoint;
202+
197203
fnchars(&self) ->implIterator<Item =Self::Char>{
198204
self.code_points()
199205
}
206+
200207
fnlen(&self) ->usize{
201208
(**self).len()
202209
}
210+
203211
fnconcat(mutself,other:Self) ->Self{
204212
self.extend([other]);
205213
self
@@ -210,19 +218,23 @@ impl FormatChar for CodePoint {
210218
fnto_char_lossy(self) ->char{
211219
self.to_char_lossy()
212220
}
221+
213222
fneq_char(self,c:char) ->bool{
214223
self == c
215224
}
216225
}
217226

218227
implFormatBufforVec<u8>{
219228
typeChar =u8;
229+
220230
fnchars(&self) ->implIterator<Item =Self::Char>{
221231
self.iter().copied()
222232
}
233+
223234
fnlen(&self) ->usize{
224235
self.len()
225236
}
237+
226238
fnconcat(mutself,other:Self) ->Self{
227239
self.extend(other);
228240
self
@@ -233,6 +245,7 @@ impl FormatChar for u8 {
233245
fnto_char_lossy(self) ->char{
234246
self.into()
235247
}
248+
236249
fneq_char(self,c:char) ->bool{
237250
char::from(self) == c
238251
}
@@ -393,6 +406,7 @@ impl CFormatSpec {
393406
Some(&(CFormatQuantity::Amount(1).into())),
394407
)
395408
}
409+
396410
pubfnformat_bytes(&self,bytes:&[u8]) ->Vec<u8>{
397411
let bytes =ifletSome(CFormatPrecision::Quantity(CFormatQuantity::Amount(precision))) =
398412
self.precision
@@ -706,12 +720,12 @@ pub enum CFormatPart<T> {
706720

707721
impl<T>CFormatPart<T>{
708722
#[inline]
709-
pubfnis_specifier(&self) ->bool{
723+
pubconstfnis_specifier(&self) ->bool{
710724
matches!(self,CFormatPart::Spec{ ..})
711725
}
712726

713727
#[inline]
714-
pubfnhas_key(&self) ->bool{
728+
pubconstfnhas_key(&self) ->bool{
715729
matchself{
716730
CFormatPart::Spec(s) => s.mapping_key.is_some(),
717731
_ =>false,
@@ -803,6 +817,7 @@ impl<S> CFormatStrOrBytes<S> {
803817
impl<S>IntoIteratorforCFormatStrOrBytes<S>{
804818
typeItem =(usize,CFormatPart<S>);
805819
typeIntoIter = std::vec::IntoIter<Self::Item>;
820+
806821
fninto_iter(self) ->Self::IntoIter{
807822
self.parts.into_iter()
808823
}

‎common/src/encodings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl ops::Add for StrSize {
121121
}
122122
}
123123
}
124+
124125
impl ops::AddAssignforStrSize{
125126
fnadd_assign(&mutself,rhs:Self){
126127
self.bytes += rhs.bytes;
@@ -133,6 +134,7 @@ struct DecodeError<'a> {
133134
rest:&'a[u8],
134135
err_len:Option<usize>,
135136
}
137+
136138
/// # Safety
137139
/// `v[..valid_up_to]` must be valid utf8
138140
unsafefnmake_decode_err(v:&[u8],valid_up_to:usize,err_len:Option<usize>) ->DecodeError<'_>{
@@ -152,6 +154,7 @@ enum HandleResult<'a> {
152154
reason:&'astr,
153155
},
154156
}
157+
155158
fndecode_utf8_compatible<Ctx,E,DecodeF,ErrF>(
156159
mutctx:Ctx,
157160
errors:&E,

‎common/src/fileutils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub mod windows {
256256
}
257257
}
258258

259-
fnattributes_to_mode(attr:u32) ->u16{
259+
constfnattributes_to_mode(attr:u32) ->u16{
260260
letmut m =0;
261261
if attr&FILE_ATTRIBUTE_DIRECTORY !=0{
262262
m |= libc::S_IFDIR |0o111;// IFEXEC for user,group,other
@@ -362,6 +362,7 @@ pub mod windows {
362362
}
363363
}
364364
}
365+
365366
pubfnstat_basic_info_to_stat(info:&FILE_STAT_BASIC_INFORMATION) ->StatStruct{
366367
use windows_sys::Win32::Storage::FileSystem;
367368
use windows_sys::Win32::System::Ioctl;

‎common/src/float_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use malachite_bigint::{BigInt, ToBigInt};
22
use num_traits::{Float,Signed,ToPrimitive,Zero};
33
use std::f64;
44

5-
pubfndecompose_float(value:f64) ->(f64,i32){
5+
pubconstfndecompose_float(value:f64) ->(f64,i32){
66
if0.0 == value{
77
(0.0,0i32)
88
}else{
@@ -63,7 +63,7 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
6363
}
6464
}
6565

66-
pubfndiv(v1:f64,v2:f64) ->Option<f64>{
66+
pubconstfndiv(v1:f64,v2:f64) ->Option<f64>{
6767
if v2 !=0.0{Some(v1 / v2)}else{None}
6868
}
6969

‎common/src/format.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl FormatSpec {
392392
}
393393
}
394394

395-
fnget_separator_interval(&self) ->usize{
395+
constfnget_separator_interval(&self) ->usize{
396396
matchself.format_type{
397397
Some(FormatType::Binary |FormatType::Octal |FormatType::Hex(_)) =>4,
398398
Some(FormatType::Decimal |FormatType::Number(_) |FormatType::FixedPoint(_)) =>3,
@@ -677,7 +677,7 @@ struct AsciiStr<'a> {
677677
}
678678

679679
impl<'a>AsciiStr<'a>{
680-
fnnew(inner:&'astr) ->Self{
680+
constfnnew(inner:&'astr) ->Self{
681681
Self{ inner}
682682
}
683683
}
@@ -690,6 +690,7 @@ impl CharLen for AsciiStr<'_> {
690690

691691
implDerefforAsciiStr<'_>{
692692
typeTarget =str;
693+
693694
fnderef(&self) ->&Self::Target{
694695
self.inner
695696
}

‎common/src/hash.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct HashSecret {
3232

3333
implBuildHasherforHashSecret{
3434
typeHasher =SipHasher24;
35+
3536
fnbuild_hasher(&self) ->Self::Hasher{
3637
SipHasher24::new_with_keys(self.k0,self.k1)
3738
}
@@ -80,7 +81,7 @@ impl HashSecret {
8081
}
8182

8283
#[inline]
83-
pubfnhash_pointer(value:usize) ->PyHash{
84+
pubconstfnhash_pointer(value:usize) ->PyHash{
8485
// TODO: 32bit?
8586
let hash =(value >>4) | value;
8687
hashas_
@@ -140,17 +141,17 @@ pub fn hash_bigint(value: &BigInt) -> PyHash {
140141
}
141142

142143
#[inline]
143-
pubfnhash_usize(data:usize) ->PyHash{
144+
pubconstfnhash_usize(data:usize) ->PyHash{
144145
fix_sentinel(mod_int(dataasi64))
145146
}
146147

147148
#[inline(always)]
148-
pubfnfix_sentinel(x:PyHash) ->PyHash{
149+
pubconstfnfix_sentinel(x:PyHash) ->PyHash{
149150
if x ==SENTINEL{ -2}else{ x}
150151
}
151152

152153
#[inline]
153-
pubfnmod_int(value:i64) ->PyHash{
154+
pubconstfnmod_int(value:i64) ->PyHash{
154155
value %MODULUSasi64
155156
}
156157

‎common/src/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
128128
}
129129

130130
#[inline]
131-
pubfndetect_base(c:&u8) ->Option<u32>{
131+
pubconstfndetect_base(c:&u8) ->Option<u32>{
132132
let base =match c{
133133
b'x' |b'X' =>16,
134134
b'b' |b'B' =>2,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp