Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Replace BigDecimal#!= by BigDecimal#nonzero?. #4199
The comparison is very expensive, because it first tries to convert the operand (which is a constant Integer 0 here) into a BigDecimal. This in turn is very expensive (because the Integer is first converted into a String, and then, for operating on that String, a java.util.regex.Pattern object is compiled (in line https://github.com/felixvf/jruby/blob/cc79119315496ea019496affe7a6a79ebc1dbed9/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java#L533)). Using #nonzero? should speed-up the loop considerably.