Skip to content

replace singular statement ++/-- with += 1/-= 1 for integer variables #556

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

Merged

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Dec 15, 2015

I busted out sed and replaced all the one-line ++ and -- statements in Swift files, then filtered out the results gradually until all tests passed in "check-swift-all".

Please let me know if breaking this up to multiple commit/PR is more desirable.

@dduan dduan changed the title replaced singular statement ++/-- with +=/-= replaced singular statement ++/-- with += 1/-= 1 Dec 15, 2015
@dduan dduan changed the title replaced singular statement ++/-- with += 1/-= 1 replace singular statement ++/-- with += 1/-= 1 Dec 15, 2015
@gribozavr gribozavr self-assigned this Dec 15, 2015
++matchIndex
++needleIndex
matchIndex += 1
needleIndex += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

This part does not compile on Linux:

swift/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift:60:20: error: binary operator '+=' cannot be applied to operands of type 'String.UnicodeScalarView.Index' and 'Int'

@gribozavr
Copy link
Contributor

@dduan Could you fix the compilation issue on Linux? Just omitting that part of the patch should be fine. Please squash patches after that fix.

@nadavrot I have reviewed the patch, and it only affects variables typed as integers. Do you have performance concerns with this kind of change?

@dabrahams
Copy link
Contributor

When advancing something that is primarily an index, x = x.successor() may be more appropriate than x += 1 even when you happen to know it's an integer. Please consider each case carefully; thanks.

@dduan dduan force-pushed the increment_decrement_search_replace branch from 0302ecb to ebb0c3a Compare December 15, 2015 17:05
@dduan
Copy link
Contributor Author

dduan commented Dec 15, 2015

@gribozavr done.

@dduan
Copy link
Contributor Author

dduan commented Dec 15, 2015

@dabrahams Ahah! It just happens so that after sed, I had to leave a lot of ++/-- statement unchanged because they are for Index types, which can't be operand of +=/-=. You just give me an idea for the next patch :P

@nadavrot
Copy link
Contributor

@gribozavr Thanks for checking with me. We'll track the performance of this change after it lands. I don't have any objections for committing this patch.

@dduan dduan changed the title replace singular statement ++/-- with += 1/-= 1 replace singular statement ++/-- with += 1/-= 1 for integer variables Dec 15, 2015
gribozavr added a commit that referenced this pull request Dec 16, 2015
replace singular statement ++/-- with += 1/-= 1 for integer variables
@gribozavr gribozavr merged commit d864cfc into swiftlang:master Dec 16, 2015
@falcon03
Copy link

Is there any reason for the removal of these (extremely handy) operators, other than the (extremely debatable IMHO) ones exposed at

https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

Not to mention the fact that we’re not sure wether
let x = 1
x += 1

can have the same performance as
let x = 1
x++

(and the same applies for the — operator)

If discussion can still be reopened I’d like to share my opinions on the “disadvantages” exposed in the previously linked change proposal.

Il giorno 16 dic 2015, alle ore 02:40, Dmitri Gribenko [email protected] ha scritto:

Merged #556 #556.


Reply to this email directly or view it on GitHub #556 (comment).

--
ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli
Clicca qui http://posta.email.it/caselle-di-posta-z-email-it/?utm_campaign=email_Zimbra_102014=main_footer/f

Sponsor:
Soluzioni di email hosting per tutte le esigenze: dalle caselle gratuite a quelle professionali su piattaforma Zimbra, da quelle su proprio dominio a quelle certificate PEC. Confronta le soluzioni
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13325&d=16-12

@gribozavr
Copy link
Contributor

@falcon03 You are welcome to send your arguments to [email protected].

@dduan dduan deleted the increment_decrement_search_replace branch December 23, 2019 21:49
freak4pc pushed a commit to freak4pc/swift that referenced this pull request Sep 28, 2022
[Stress tester XFails] Update XFails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants