Skip to content

Commit

Permalink
Merge pull request capnproto#345 from danieleades/use-of-ref
Browse files Browse the repository at this point in the history
remove unnecessary use of 'ref'
  • Loading branch information
dwrensha authored Nov 21, 2022
2 parents 02b38ee + d03cb09 commit 8f1cad4
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 119 deletions.
5 changes: 1 addition & 4 deletions benchmark/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ impl<'a> Scratch<'a> for UseScratch {
type Allocator = message::ScratchSpaceHeapAllocator<'a>;

fn get_allocators(&'a mut self) -> (Self::Allocator, Self::Allocator) {
let UseScratch {
ref mut buffer1,
ref mut buffer2,
} = self;
let UseScratch { buffer1, buffer2 } = self;
(
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer1)),
message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer2)),
Expand Down
14 changes: 7 additions & 7 deletions capnp-rpc/src/queued.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl PipelineHook for Pipeline {
}

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

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

Expand Down Expand Up @@ -288,20 +288,20 @@ impl ClientHook for Client {
}

fn get_resolved(&self) -> Option<Box<dyn ClientHook>> {
match self.inner.borrow().redirect {
Some(ref inner) => Some(inner.clone()),
match &self.inner.borrow().redirect {
Some(inner) => Some(inner.clone()),
None => None,
}
}

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

let promise = self.inner.borrow_mut().client_resolution_queue.push(());
match self.inner.borrow().promise_to_drive {
Some(ref p) => Some(Promise::from_future(
match &self.inner.borrow().promise_to_drive {
Some(p) => Some(Promise::from_future(
futures::future::try_join(p.clone(), promise).map_ok(|v| v.1),
)),
None => Some(Promise::from_future(promise)),
Expand Down
146 changes: 62 additions & 84 deletions capnp-rpc/src/rpc.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions capnp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,18 @@ pub enum OutputSegments<'a> {
impl<'a> core::ops::Deref for OutputSegments<'a> {
type Target = [&'a [u8]];
fn deref(&self) -> &[&'a [u8]] {
match *self {
OutputSegments::SingleSegment(ref s) => s,
OutputSegments::MultiSegment(ref v) => v,
match self {
OutputSegments::SingleSegment(s) => s,
OutputSegments::MultiSegment(v) => v,
}
}
}

impl<'s> message::ReaderSegments for OutputSegments<'s> {
fn get_segment(&self, id: u32) -> Option<&[u8]> {
match *self {
OutputSegments::SingleSegment(ref s) => s.get(id as usize).copied(),
OutputSegments::MultiSegment(ref v) => v.get(id as usize).copied(),
match self {
OutputSegments::SingleSegment(s) => s.get(id as usize).copied(),
OutputSegments::MultiSegment(v) => v.get(id as usize).copied(),
}
}
}
2 changes: 1 addition & 1 deletion capnp/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ where
}
let (seg_start, _seg_len) = self.arena.get_segment_mut(0);
let location: *mut u8 = seg_start;
let Self { ref mut arena } = *self;
let Self { arena } = self;

any_pointer::Builder::new(layout::PointerBuilder::get_root(arena, 0, location))
}
Expand Down
6 changes: 3 additions & 3 deletions capnp/src/private/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ where
{
/// Allocates a new segment with capacity for at least `minimum_size` words.
fn allocate_segment(&mut self, minimum_size: WordCount32) -> Result<()> {
let seg = match self.allocator {
Some(ref mut a) => a.allocate_segment(minimum_size),
let seg = match &mut self.allocator {
Some(a) => a.allocate_segment(minimum_size),
None => unreachable!(),
};
self.segments.push(BuilderSegment {
Expand Down Expand Up @@ -332,7 +332,7 @@ where
}

fn deallocate_all(&mut self) {
if let Some(ref mut a) = self.allocator {
if let Some(a) = &mut self.allocator {
for seg in &self.segments {
a.deallocate_segment(seg.ptr, seg.capacity, seg.allocated);
}
Expand Down
10 changes: 2 additions & 8 deletions capnp/src/private/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2750,10 +2750,7 @@ impl CapTableReader {
if index >= hooks.len() {
None
} else {
match hooks[index] {
None => None,
Some(ref hook) => Some(hook.add_ref()),
}
hooks[index].as_ref().map(|hook| hook.add_ref())
}
}
}
Expand Down Expand Up @@ -2785,10 +2782,7 @@ impl CapTableBuilder {
if index >= hooks.len() {
None
} else {
match hooks[index] {
None => None,
Some(ref hook) => Some(hook.add_ref()),
}
hooks[index].as_ref().map(|hook| hook.add_ref())
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions capnpc/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CodeGenerationCommand {
// It would be simpler to use the ? operator instead of a pattern match, but then the error message
// would not include `filepath`.
match ::std::fs::File::create(&filepath) {
Ok(ref mut writer) => {
Ok(mut writer) => {
writer.write_all(text.as_bytes()).map_err(convert_io_err)?;
}
Err(e) => {
Expand Down Expand Up @@ -325,9 +325,9 @@ pub enum FormattedText {
}

fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
match *ft {
Indent(ref ft) => to_lines(ft, indent + 1),
Branch(ref fts) => {
match ft {
Indent(ft) => to_lines(ft, indent + 1),
Branch(fts) => {
let mut result = Vec::new();
for ft in fts.iter() {
for line in &to_lines(ft, indent) {
Expand All @@ -336,7 +336,7 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
}
result
}
Line(ref s) => {
Line(s) => {
let mut s1: String = " ".repeat(indent * 2);
s1.push_str(s);
vec![s1.to_string()]
Expand Down Expand Up @@ -1057,7 +1057,7 @@ fn generate_setter(
}
}
};
if let Some(ref reader_type) = maybe_reader_type {
if let Some(reader_type) = &maybe_reader_type {
let return_type = if return_result {
"-> ::capnp::Result<()>"
} else {
Expand Down

0 comments on commit 8f1cad4

Please sign in to comment.