Skip to content

Commit 8f1cad4

Browse files
authored
Merge pull request capnproto#345 from danieleades/use-of-ref
remove unnecessary use of 'ref'
2 parents 02b38ee + d03cb09 commit 8f1cad4

File tree

8 files changed

+88
-119
lines changed

8 files changed

+88
-119
lines changed

benchmark/benchmark.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ impl<'a> Scratch<'a> for UseScratch {
174174
type Allocator = message::ScratchSpaceHeapAllocator<'a>;
175175

176176
fn get_allocators(&'a mut self) -> (Self::Allocator, Self::Allocator) {
177-
let UseScratch {
178-
ref mut buffer1,
179-
ref mut buffer2,
180-
} = self;
177+
let UseScratch { buffer1, buffer2 } = self;
181178
(
182179
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer1)),
183180
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer2)),

capnp-rpc/src/queued.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl PipelineHook for Pipeline {
143143
}
144144

145145
fn get_pipelined_cap_move(&self, ops: Vec<PipelineOp>) -> Box<dyn ClientHook> {
146-
if let Some(ref p) = self.inner.borrow().redirect {
146+
if let Some(p) = &self.inner.borrow().redirect {
147147
return p.get_pipelined_cap_move(ops);
148148
}
149149

@@ -258,7 +258,7 @@ impl ClientHook for Client {
258258
params: Box<dyn ParamsHook>,
259259
results: Box<dyn ResultsHook>,
260260
) -> Promise<(), Error> {
261-
if let Some(ref client) = self.inner.borrow().redirect {
261+
if let Some(client) = &self.inner.borrow().redirect {
262262
return client.call(interface_id, method_id, params, results);
263263
}
264264

@@ -288,20 +288,20 @@ impl ClientHook for Client {
288288
}
289289

290290
fn get_resolved(&self) -> Option<Box<dyn ClientHook>> {
291-
match self.inner.borrow().redirect {
292-
Some(ref inner) => Some(inner.clone()),
291+
match &self.inner.borrow().redirect {
292+
Some(inner) => Some(inner.clone()),
293293
None => None,
294294
}
295295
}
296296

297297
fn when_more_resolved(&self) -> Option<Promise<Box<dyn ClientHook>, Error>> {
298-
if let Some(ref client) = self.inner.borrow().redirect {
298+
if let Some(client) = &self.inner.borrow().redirect {
299299
return Some(Promise::ok(client.add_ref()));
300300
}
301301

302302
let promise = self.inner.borrow_mut().client_resolution_queue.push(());
303-
match self.inner.borrow().promise_to_drive {
304-
Some(ref p) => Some(Promise::from_future(
303+
match &self.inner.borrow().promise_to_drive {
304+
Some(p) => Some(Promise::from_future(
305305
futures::future::try_join(p.clone(), promise).map_ok(|v| v.1),
306306
)),
307307
None => Some(Promise::from_future(promise)),

capnp-rpc/src/rpc.rs

Lines changed: 62 additions & 84 deletions
Large diffs are not rendered by default.

capnp/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,18 @@ pub enum OutputSegments<'a> {
287287
impl<'a> core::ops::Deref for OutputSegments<'a> {
288288
type Target = [&'a [u8]];
289289
fn deref(&self) -> &[&'a [u8]] {
290-
match *self {
291-
OutputSegments::SingleSegment(ref s) => s,
292-
OutputSegments::MultiSegment(ref v) => v,
290+
match self {
291+
OutputSegments::SingleSegment(s) => s,
292+
OutputSegments::MultiSegment(v) => v,
293293
}
294294
}
295295
}
296296

297297
impl<'s> message::ReaderSegments for OutputSegments<'s> {
298298
fn get_segment(&self, id: u32) -> Option<&[u8]> {
299-
match *self {
300-
OutputSegments::SingleSegment(ref s) => s.get(id as usize).copied(),
301-
OutputSegments::MultiSegment(ref v) => v.get(id as usize).copied(),
299+
match self {
300+
OutputSegments::SingleSegment(s) => s.get(id as usize).copied(),
301+
OutputSegments::MultiSegment(v) => v.get(id as usize).copied(),
302302
}
303303
}
304304
}

capnp/src/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ where
419419
}
420420
let (seg_start, _seg_len) = self.arena.get_segment_mut(0);
421421
let location: *mut u8 = seg_start;
422-
let Self { ref mut arena } = *self;
422+
let Self { arena } = self;
423423

424424
any_pointer::Builder::new(layout::PointerBuilder::get_root(arena, 0, location))
425425
}

capnp/src/private/arena.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ where
289289
{
290290
/// Allocates a new segment with capacity for at least `minimum_size` words.
291291
fn allocate_segment(&mut self, minimum_size: WordCount32) -> Result<()> {
292-
let seg = match self.allocator {
293-
Some(ref mut a) => a.allocate_segment(minimum_size),
292+
let seg = match &mut self.allocator {
293+
Some(a) => a.allocate_segment(minimum_size),
294294
None => unreachable!(),
295295
};
296296
self.segments.push(BuilderSegment {
@@ -332,7 +332,7 @@ where
332332
}
333333

334334
fn deallocate_all(&mut self) {
335-
if let Some(ref mut a) = self.allocator {
335+
if let Some(a) = &mut self.allocator {
336336
for seg in &self.segments {
337337
a.deallocate_segment(seg.ptr, seg.capacity, seg.allocated);
338338
}

capnp/src/private/layout.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,10 +2750,7 @@ impl CapTableReader {
27502750
if index >= hooks.len() {
27512751
None
27522752
} else {
2753-
match hooks[index] {
2754-
None => None,
2755-
Some(ref hook) => Some(hook.add_ref()),
2756-
}
2753+
hooks[index].as_ref().map(|hook| hook.add_ref())
27572754
}
27582755
}
27592756
}
@@ -2785,10 +2782,7 @@ impl CapTableBuilder {
27852782
if index >= hooks.len() {
27862783
None
27872784
} else {
2788-
match hooks[index] {
2789-
None => None,
2790-
Some(ref hook) => Some(hook.add_ref()),
2791-
}
2785+
hooks[index].as_ref().map(|hook| hook.add_ref())
27922786
}
27932787
}
27942788
}

capnpc/src/codegen.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl CodeGenerationCommand {
128128
// It would be simpler to use the ? operator instead of a pattern match, but then the error message
129129
// would not include `filepath`.
130130
match ::std::fs::File::create(&filepath) {
131-
Ok(ref mut writer) => {
131+
Ok(mut writer) => {
132132
writer.write_all(text.as_bytes()).map_err(convert_io_err)?;
133133
}
134134
Err(e) => {
@@ -325,9 +325,9 @@ pub enum FormattedText {
325325
}
326326

327327
fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
328-
match *ft {
329-
Indent(ref ft) => to_lines(ft, indent + 1),
330-
Branch(ref fts) => {
328+
match ft {
329+
Indent(ft) => to_lines(ft, indent + 1),
330+
Branch(fts) => {
331331
let mut result = Vec::new();
332332
for ft in fts.iter() {
333333
for line in &to_lines(ft, indent) {
@@ -336,7 +336,7 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
336336
}
337337
result
338338
}
339-
Line(ref s) => {
339+
Line(s) => {
340340
let mut s1: String = " ".repeat(indent * 2);
341341
s1.push_str(s);
342342
vec![s1.to_string()]
@@ -1057,7 +1057,7 @@ fn generate_setter(
10571057
}
10581058
}
10591059
};
1060-
if let Some(ref reader_type) = maybe_reader_type {
1060+
if let Some(reader_type) = &maybe_reader_type {
10611061
let return_type = if return_result {
10621062
"-> ::capnp::Result<()>"
10631063
} else {

0 commit comments

Comments
 (0)