Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to move ByteStrings underlying bytes #9684

Merged
merged 2 commits into from Feb 19, 2016
Merged

Conversation

@dlrobertson
Copy link
Contributor

dlrobertson commented Feb 17, 2016

Add methods to move the underlying Vec<u8> for ByteString.

I saw this as at least two methods. One to "move and replace with and empty Vec (bytes), and one to take ownership of the whole object (own_bytes). I typically also don't like adding methods with out unit tests. If you think they're unnecessary, just let me know.

As always, please let me know if you have any comments, critiques, or nits!

Fixes #9655

Review on Reviewable

@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 17, 2016

@dlrobertson
Copy link
Contributor Author

dlrobertson commented Feb 17, 2016

Review status: 0 of 4 files reviewed at latest revision, 1 unresolved discussion.


components/script/dom/bindings/str.rs, line 46 [r1] (raw file):
Saw the function was using the older method, so I simplified it.


Comments from the review on Reviewable.io

@dlrobertson dlrobertson force-pushed the dlrobertson:i9655 branch from 7f33251 to e86fa36 Feb 17, 2016
@KiChjang
Copy link
Member

KiChjang commented Feb 18, 2016

Wow, this is pretty good work, thanks for your contribution!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 18, 2016

📌 Commit e86fa36 has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Feb 18, 2016

Testing commit e86fa36 with merge 0666df5...

bors-servo added a commit that referenced this pull request Feb 18, 2016
Add methods to move ByteStrings underlying bytes

Add methods to move the underlying `Vec<u8>` for `ByteString`.

I saw this as at least two methods. One to "move and replace with and empty Vec<u8> (`bytes`), and one to take ownership of the whole object (`own_bytes`). I typically also don't like adding methods with out unit tests. If you think they're unnecessary, just let me know.

As always, please let me know if you have any comments, critiques, or nits!

Fixes: #9655

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9684)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 18, 2016

💔 Test failed - linux-rel

@@ -28,10 +29,21 @@ impl ByteString {
str::from_utf8(&vec).ok()
}

/// Returns ownership of the underlying Vec<u8> the ByteString is
/// unusable afterwards as it has been moved

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 18, 2016

Member

Takes ownership of the underlying Vec<u8>. The ByteString is unusable afterwards.

This comment has been minimized.

Copy link
@dlrobertson

dlrobertson Feb 18, 2016

Author Contributor

Much better documentation!

@@ -28,10 +29,21 @@ impl ByteString {
str::from_utf8(&vec).ok()
}

/// Returns ownership of the underlying Vec<u8> the ByteString is
/// unusable afterwards as it has been moved
pub fn own_bytes(self) -> Vec<u8> {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 18, 2016

Member

I'm thinking that this should be instead named into_bytes to be consistent with std namings.

This comment has been minimized.

Copy link
@dlrobertson

dlrobertson Feb 18, 2016

Author Contributor

Ah! Good point! I thought about something like drain_bytes, but we'll go with into_bytes.


/// Takes ownership of the underlying Vec<u8>. The ByteString is
/// unusable afterwards.
pub fn own_bytes(self) -> Vec<u8> {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 18, 2016

Member

I meant this method to be renamed into_bytes.


/// Returns ownership of the underlying Vec<u8> and copies an empty
/// vec in its place
pub fn into_bytes(&mut self) -> Vec<u8> {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Feb 18, 2016

Member

bytes is fine.

This comment has been minimized.

Copy link
@dlrobertson

dlrobertson Feb 18, 2016

Author Contributor

Oh, my bad! One sec

@dlrobertson dlrobertson force-pushed the dlrobertson:i9655 branch from 3399282 to e1fbbee Feb 18, 2016
@dlrobertson dlrobertson force-pushed the dlrobertson:i9655 branch from e1fbbee to a4280cd Feb 18, 2016
Add methods to move the underlying Vec<u8> for ByteString.
Convert traditional unwrapping of the tuple struct ByteString to
self.0
@dlrobertson dlrobertson force-pushed the dlrobertson:i9655 branch from a4280cd to 72f74c2 Feb 18, 2016
@KiChjang
Copy link
Member

KiChjang commented Feb 19, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

📌 Commit 72f74c2 has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

Testing commit 72f74c2 with merge 126f41b...

bors-servo added a commit that referenced this pull request Feb 19, 2016
Add methods to move ByteStrings underlying bytes

Add methods to move the underlying `Vec<u8>` for `ByteString`.

I saw this as at least two methods. One to "move and replace with and empty Vec<u8> (`bytes`), and one to take ownership of the whole object (`own_bytes`). I typically also don't like adding methods with out unit tests. If you think they're unnecessary, just let me know.

As always, please let me know if you have any comments, critiques, or nits!

Fixes #9655

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9684)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 19, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

Testing commit 72f74c2 with merge aae6525...

bors-servo added a commit that referenced this pull request Feb 19, 2016
Add methods to move ByteStrings underlying bytes

Add methods to move the underlying `Vec<u8>` for `ByteString`.

I saw this as at least two methods. One to "move and replace with and empty Vec<u8> (`bytes`), and one to take ownership of the whole object (`own_bytes`). I typically also don't like adding methods with out unit tests. If you think they're unnecessary, just let me know.

As always, please let me know if you have any comments, critiques, or nits!

Fixes #9655

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9684)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 19, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

Previous build results for android, gonk, linux-dev, mac-dev-unit, mac-rel-css are reusable. Rebuilding only linux-rel, mac-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Feb 19, 2016

@bors-servo bors-servo merged commit 72f74c2 into servo:master Feb 19, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@dlrobertson dlrobertson deleted the dlrobertson:i9655 branch Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.