News for hackers. Stuff that matters.
Re:Apple Lossless Decoder in Coffeescript by nitrogen on Monday December 19, 2011 @09:15PM (#3372012)
What if you compiled it something like this:

  for i in [a...b]
becomes

  if(a <= b) {
      for(i = a; i < b; i++) {
          // Code
      }
  } else {
      for(i = a; i > b; i--) {
          // Code again
      }
  }
Or otherwise moved the extra conditions outside the loop so they only get computed once?
Re:Apple Lossless Decoder in Coffeescript by jashkenas on Monday December 19, 2011 @09:28PM (#3372046)
Unfortunately, that requires repeating the entire body of the loop, and so isn't workable/acceptable for our purposes. If you'd like to see the original conversation that led to the current compilation, it's all available on the GitHub issues.
Re:Apple Lossless Decoder in Coffeescript by repsilat on Tuesday December 20, 2011 @01:54AM (#3372579)
I'll have a look for the discussion. Any idea if the branches are more expensive than some multiplies?

    step = (a<=b)?1:-1;
    for (i = a; step*i < step*b; i += step) {
      doSomething();
    }
I guess if the branch predictor is any good it could be slower with multiplies, but I have no idea what to expect in a dynamic language.