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

Turn flow::base and friends into methods #19565

Merged
merged 1 commit into from Dec 15, 2017
Merged

Turn flow::base and friends into methods #19565

merged 1 commit into from Dec 15, 2017

Conversation

@mbrubeck
Copy link
Contributor

mbrubeck commented Dec 14, 2017

This feels more idiomatic in modern Rust, and replaces code like this:

flow::base(&**root_flow).restyle_damage

with this:

root_flow.base().restyle_damage.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because they are refactoring only

This change is Reviewable

@highfive
Copy link

highfive commented Dec 14, 2017

Heads up! This PR modifies the following files:

  • @emilio: components/layout/construct.rs, components/layout/fragment.rs, components/layout/traversal.rs, components/layout/incremental.rs, components/layout/sequential.rs and 14 more
@highfive
Copy link

highfive commented Dec 14, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify layout code, but no tests are modified. Please consider adding a test!
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Dec 14, 2017

cc @pcwalton

You wrote in a 2013 comment here that adding "virtual methods" to the Flow trait has a cost. Can you elaborate on that? Is it still true today?

/// Note that virtual methods have a cost; we should not overuse them in Servo. Consider adding

@emilio
Copy link
Member

emilio commented Dec 14, 2017

Well, you pay the virtual call, I suppose...

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Dec 14, 2017

Well, you pay the virtual call, I suppose...

Oh right, while calling flow::base on an &Flow argument isn't virtual, because it operates directly on the data pointer (and ignores the vtable pointer). Hmm.

@mbrubeck mbrubeck force-pushed the mbrubeck:base branch from 7da484d to 9f4a00d Dec 14, 2017
@mbrubeck mbrubeck changed the title Turn flow::base and friends into Flow trait methods Turn flow::base and friends into methods Dec 14, 2017
@mbrubeck mbrubeck force-pushed the mbrubeck:base branch from 9f4a00d to f341d65 Dec 14, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Dec 14, 2017

Moved these methods to a separate trait that is implemented directly on both sized and unsized types, to avoid virtual calls.

@mbrubeck mbrubeck force-pushed the mbrubeck:base branch from f341d65 to c60cfc5 Dec 14, 2017
@@ -76,6 +76,30 @@ use table_wrapper::TableWrapperFlow;
#[allow(unsafe_code)]
pub unsafe trait HasBaseFlow {}

/// Methods to get the `BaseFlow` from any `HasBaseFlow` type.
pub trait GetBaseFlow {

This comment has been minimized.

@KiChjang

KiChjang Dec 14, 2017

Member

Why not let HasBaseFlow become a super trait of GetBaseFlow instead?

This comment has been minimized.

@mbrubeck

mbrubeck Dec 15, 2017

Author Contributor

Making this trait GetBaseFlow: HasBaseFlow works, but I'm not sure if it adds anything. There's no technical reason for this trait to require HasBaseFlow for all impls.

@emilio
Copy link
Member

emilio commented Dec 15, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

📌 Commit c60cfc5 has been approved by emilio

@highfive highfive assigned emilio and unassigned metajack Dec 15, 2017
@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

Testing commit c60cfc5 with merge 072029a...

bors-servo added a commit that referenced this pull request Dec 15, 2017
Turn flow::base and friends into methods

This feels more idiomatic in modern Rust, and replaces code like this:

`flow::base(&**root_flow).restyle_damage`

with this:

`root_flow.base().restyle_damage`.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they are refactoring only

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19565)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

💔 Test failed - mac-dev-unit

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Dec 15, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

Testing commit c60cfc5 with merge 53968fe...

bors-servo added a commit that referenced this pull request Dec 15, 2017
Turn flow::base and friends into methods

This feels more idiomatic in modern Rust, and replaces code like this:

`flow::base(&**root_flow).restyle_damage`

with this:

`root_flow.base().restyle_damage`.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they are refactoring only

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19565)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

💔 Test failed - mac-rel-wpt3

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Dec 15, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2017

@bors-servo bors-servo merged commit c60cfc5 into servo:master Dec 15, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
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

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