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

src: add incr/decr operators for Reference #19083

Closed

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Mar 2, 2018

This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

src

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Mar 2, 2018
@danbev
Copy link
Contributor Author

danbev commented Mar 2, 2018

@danbev
Copy link
Contributor Author

danbev commented Mar 2, 2018

node-test-commit-windows-fanned failure looks unrelated

console output:

not ok 230 parallel/test-http2-https-fallback
  ---
  duration_ms: 0.264
  severity: fail
  stack: |-
    (node:3544) ExperimentalWarning: The http2 module is an experimental API.
    assert.js:243
        throw err;
        ^
    
    AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
    
      assert.ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text))
    
        at TLSSocket.tls.setEncoding.on.on.common.mustCall (c:\workspace\node-test-binary-windows\test\parallel\test-http2-https-fallback.js:143:9)
        at TLSSocket.<anonymous> (c:\workspace\node-test-binary-windows\test\common\index.js:467:15)
        at TLSSocket.emit (events.js:136:15)
        at endReadableNT (_stream_readable.js:1021:12)
        at process._tickCallback (internal/process/next_tick.js:115:19)
  ...

@richardlau
Copy link
Member

richardlau commented Mar 2, 2018

node-test-commit-windows-fanned failure looks unrelated

      assert.ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text))
   
       at TLSSocket.tls.setEncoding.on.on.common.mustCall (c:\workspace\node-test-binary-windows\test\parallel\test-http2-https-fallback.js:143:9)

This assert was recently introduced in #18986
cc @addaleax

Update: being addressed by #19093.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 2, 2018
template <typename T>
inline Reference& operator-=(const T& val) {
const T current = aliased_buffer_->GetValue(index_);
aliased_buffer_->SetValue(index_, current - val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I’m missing something, you could just do operator+=(index_, -val) here. If you add an overload for the unary minus operator (or is that even necessary?), that should get rid of the overload below that takes in a const Reference&.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a closer look at your suggestion on Monday (little short of time right now). Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu Please take a look and see if this was what you had in mind, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu If possible I'd like get this merged but it would be great if you could take a look at the latest change and see if this is what you had in mind. Thanks

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

}

inline Reference& operator-=(const Reference& val) {
this->operator-=(static_cast<NativeT>(val));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion, but I would personally find return *this -= static_cast<NativeT>(val); a bit clearer/more idiomatic in these places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, let me change that thanks!

@danbev
Copy link
Contributor Author

danbev commented Mar 5, 2018

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely still merge-able :)


template <typename T>
inline Reference& operator-=(const T& val) {
return this->operator+=(-val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure, this still works if val is a reference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would definitely be good to test for that.

This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.
@danbev danbev force-pushed the aliased_buffer_plus_minus_equals_overload branch from 6802731 to 18f46e8 Compare March 9, 2018 06:56
@danbev
Copy link
Contributor Author

danbev commented Mar 9, 2018

Test added and rebased CI: https://ci.nodejs.org/job/node-test-pull-request/13599/

jasnell pushed a commit that referenced this pull request Mar 9, 2018
This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.

PR-URL: #19083
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
@jasnell
Copy link
Member

jasnell commented Mar 9, 2018

Landed in 45277e2

@jasnell jasnell closed this Mar 9, 2018
@danbev danbev deleted the aliased_buffer_plus_minus_equals_overload branch March 12, 2018 05:56
targos pushed a commit that referenced this pull request Mar 17, 2018
This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.

PR-URL: #19083
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
@targos targos mentioned this pull request Mar 18, 2018
MylesBorins pushed a commit that referenced this pull request Mar 20, 2018
This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.

PR-URL: #19083
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This commit adds operator overloads for increment/decrement to
AliasedBuffer::Reference.
The motivation for doing this is to hopefully make code that needs
to increment/decrement a little simpler.

PR-URL: nodejs#19083
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

Should this be backported to 8.x? If so, a separate backport PR is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants