Skip to content

Conversation

@gibson042
Copy link
Member

Sizes - compared to master @ 53a0666

    264563       (-36)  dist/jquery.js                                         
     92213      (-190)  dist/jquery.min.js                                     
     32661      (-142)  dist/jquery.min.js.gz

@gibson042
Copy link
Member Author

@jquerybot retest

@jaubourg
Copy link
Member

FMOI, What are the patterns and why do they end up being better?

@scottgonzalez
Copy link
Member

It'd be good to get these into our style guide so that everyone knows to follow them in the future.

For example, should we always be doing for loops in the form for ( ; i < len; i++ ) { ?

@rwaldron
Copy link
Member

The style guide actually explicitly states:

"string".match() is no longer used.

...despite it being used twice in src/event.js. The rationale, IIRC, is reducing the context shifts by only using RegExp API for RegExp operations and String API for String operations.

@dmethvin
Copy link
Member

"string".match(/pattern/g) has no analog in .exec(), which is why it was used there.

@rwaldron
Copy link
Member

The pattern being matched is just /\S+/g, wouldn't split be sufficient?

@dmethvin
Copy link
Member

@jaubourg
Copy link
Member

I like the fact you don't need to trim when using match.

@gibson042
Copy link
Member Author

Other than that, there was just a little bit of cruft to cleanup.

@dmethvin
Copy link
Member

The changes look good to me in general, the -142 seems magical. Glad you found regexdash, it seems like jshint has an option for every occasion and that one was annoying.

I'm not a big fan of initializing a loop variable far away from where it's being used, but the "far away" part is more due to some of the huge complex methods we have. @mikesherov has been threatening to turn on some of the complexity metrics.

@timmywil
Copy link
Member

I asked John why that was in the styleguide and he said the point was originally the difference in null value management...

null.match(...); // => error
/\s/.exec( null ); // => `null`

However, as Dave pointed out, there is one thing you can't duplicate with exec and that is a global match. This can be very useful and Sizzle also takes advantage of this use of match. I still prefer exec in most cases.

@mikesherov
Copy link
Member

maxcomplexity ftw

On Mon, Nov 26, 2012 at 9:40 AM, Timmy Willison [email protected]:

I asked John why that was in the styleguide and he said the point was
originally the difference in null value management...

null.match(...); // => error

//.exec( null ); // => null

However, as Dave pointed out, there is one thing you can't duplicate with
exec and that is a global match. This can be very useful and Sizzle also
takes advantage of this use of match. I still prefer exec in most cases.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1046#issuecomment-10717616.

Mike Sherov
Lead Developer
SNAP Interactive, Inc.
Ticker: STVI.OB

@gibson042
Copy link
Member Author

For the record, our other common numeric iterations look like:

  • while ( i-- ) {
  • while ( (scalar = array[i++]) ) {
  • for ( ; (elem = elems[i]) != null; i++ ) { (note redundancy with the preceding)

And on node iterations:

  • while ( (node = node.DOMRelation) ) {; while ( (node = node[ dir ]) ) {
  • for ( ; cur; cur = cur.DOMRelation ) {

With lots of deviations from all of the above all over the place. To be honest, I think there's a lot more savings to be had from reducing the amount of variation here.

@gibson042 gibson042 merged commit 0766240 into jquery:master Nov 26, 2012
markelog pushed a commit to markelog/sizzle that referenced this pull request Dec 25, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants