Skip to content

Use "capacity" as parameter name in with_capacity() methods - #60316

Merged
bors merged 1 commit into
rust-lang:masterfrom
mgeier:rename-capacity-parameter
Apr 27, 2019
Merged

Use "capacity" as parameter name in with_capacity() methods#60316
bors merged 1 commit into
rust-lang:masterfrom
mgeier:rename-capacity-parameter

Conversation

@mgeier

Copy link
Copy Markdown
Contributor

See #60271.

The only place where I didn't change the parameter name is RawVec. The problem is that it has a .cap() method instead of the usual .capacity():

/// Gets the capacity of the allocation.
///
/// This will always be `usize::MAX` if `T` is zero-sized.
#[inline(always)]
pubfncap(&self) -> usize{
if mem::size_of::<T>() == 0{
!0
}else{
self.cap
}
}

Changing this would be a breaking change, and I guess that's not worth it.

But since I didn't change .cap() there, I didn't change the cap parameter name to capacity, either.

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2019
@mgeier

Copy link
Copy Markdown
ContributorAuthor

I've found two more evil .cap() methods:

impl<T>Buffer<T>{
fnenqueue(&mutself,t:T){
let pos = (self.start + self.size) % self.buf.len();
self.size += 1;
let prev = mem::replace(&mutself.buf[pos],Some(t));
assert!(prev.is_none());
}
fndequeue(&mutself) -> T{
let start = self.start;
self.size -= 1;
self.start = (self.start + 1) % self.buf.len();
let result = &mutself.buf[start];
result.take().unwrap()
}
fnsize(&self) -> usize{self.size}
fncap(&self) -> usize{self.buf.len()}
}

impl<T>VecDeque<T>{
/// Marginally more convenient
#[inline]
fnptr(&self) -> *mutT{
self.buf.ptr()
}
/// Marginally more convenient
#[inline]
fncap(&self) -> usize{
if mem::size_of::<T>() == 0{
// For zero sized types, we are always at maximum capacity
MAXIMUM_ZST_CAPACITY
}else{
self.buf.cap()
}
}

@joshtriplett

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Apr 26, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit be12ab0 has been approved by joshtriplett

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2019
@estebank

Copy link
Copy Markdown
Contributor

@bors rollup

Centril added a commit to Centril/rust that referenced this pull request Apr 27, 2019
…=joshtriplett
Use "capacity" as parameter name in with_capacity() methods
See rust-lang#60271.
The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:
https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210
Changing this would be a breaking change, and I guess that's not worth it.
But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
@CentrilCentril mentioned this pull request Apr 27, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 27, 2019
…=joshtriplett
Use "capacity" as parameter name in with_capacity() methods
See rust-lang#60271.
The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:
https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210
Changing this would be a breaking change, and I guess that's not worth it.
But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
@CentrilCentril mentioned this pull request Apr 27, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 27, 2019
…=joshtriplett
Use "capacity" as parameter name in with_capacity() methods
See rust-lang#60271.
The only place where I didn't change the parameter name is `RawVec`. The problem is that it has a `.cap()` method instead of the usual `.capacity()`:
https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/liballoc/raw_vec.rs#L200-L210
Changing this would be a breaking change, and I guess that's not worth it.
But since I didn't change `.cap()` there, I didn't change the `cap` parameter name to `capacity`, either.
@CentrilCentril mentioned this pull request Apr 27, 2019
bors added a commit that referenced this pull request Apr 27, 2019
Rollup of 5 pull requests
Successful merges:
- #60292 (Replace the `&'tcx List<Ty<'tcx>>` in `TyKind::Tuple` with `SubstsRef<'tcx>`)
- #60307 (Make "Implementations on Foreign Types" items in sidebar link to specific impls)
- #60309 (Add 1.34.1 release notes)
- #60315 (bootstrap: use correct version numbers for llvm-tools and lldb)
- #60316 (Use "capacity" as parameter name in with_capacity() methods)
Failed merges:
r? @ghost
@bors

bors commented Apr 27, 2019

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #60329) made this pull request unmergeable. Please resolve the merge conflicts.

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 27, 2019
@bors
bors merged commit be12ab0 into rust-lang:masterApr 27, 2019
@mgeier
mgeier deleted the rename-capacity-parameter branch April 27, 2019 18:22
Centril added a commit to Centril/rust that referenced this pull request Jun 26, 2019
Rename .cap() methods to .capacity()
As mentioned in rust-lang#60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code.
This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility.
I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.
bors added a commit that referenced this pull request Jul 25, 2019
Rename .cap() methods to .capacity()
As mentioned in #60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code.
This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility.
I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mgeier@rust-highfive@joshtriplett@bors@estebank