[#15701] Ruby 1.9.0-1 snapshot released — Yukihiro Matsumoto <matz@...>
Hi,
[#15704] Proc#curry doesn't work on func which produces func — Lin Jen-Shin <godfat@...>
Proc#curry doesn't work on function which produces function,
Hi,
>>>>> "Y" == Yusuke ENDOH <mame@tsg.ne.jp> writes:
[#15707] Schedule for the 1.8.7 release — "Akinori MUSHA" <knu@...>
Hi, developers,
On Sat, Mar 01, 2008 at 08:58:00PM +0900, Akinori MUSHA wrote:
Hi,
At Fri, 21 Mar 2008 23:16:54 +0900,
At Mon, 24 Mar 2008 21:39:45 +0900,
[#15709] capitalize and downcase — Trans <transfire@...>
I've always wondered why String#capitalize downcases the whole string
[#15713] Ruby String hash key overflow when converting to Fixnum. — "Chiyuan Zhang" <pluskid@...>
Hi, all! I've opened a issue at rubyforge:
[#15728] Question on build process - skipping unsupported extensions — Daniel Berger <djberg96@...>
Hi,
[#15740] Copy-on-write friendly garbage collector — Hongli Lai <hongli@...99.net>
Hi.
Hi,
Yukihiro Matsumoto wrote:
Yukihiro Matsumoto wrote:
Hi.
Hongli Lai wrote:
Hi.
Hi,
I believe I managed to close the performance gap to only 6% slower than
Daniel DeLorme wrote:
[#15746] Am I misinterpreting the new keyword arguments to IO.foreach and friends? — Dave Thomas <dave@...>
I was expecting this to pass lines to the block:
[#15756] embedding Ruby 1.9.0 inside pthread — "Suraj Kurapati" <sunaku@...>
Hello,
Hi,
Hi,
Yukihiro Matsumoto wrote:
Suraj N. Kurapati wrote:
Hi,
Nobuyoshi Nakada wrote:
Suraj N. Kurapati wrote:
Hongli Lai wrote:
[#15775] next(n), succ(n) ? — Trans <transfire@...>
Can anyone see any reason against adding an optional parameter to
[#15778] Named captures and regular captures — Dave Thomas <dave@...>
It seems that once you have a named capture in a regular expression,
[#15783] Adding startup and shutdown to Test::Unit — Daniel Berger <Daniel.Berger@...>
Hi all,
Daniel Berger wrote:
On Wed, Mar 05, 2008 at 07:52:40AM +0900, Daniel Berger wrote:
[#15835] TimeoutError in core, timeouts for ConditionVariable#wait — MenTaLguY <mental@...>
I've been reworking JRuby's stdlib to improve performance and fix
On Sun, 2008-03-09 at 12:13 +0900, MenTaLguY wrote:
[#15837] Correct procedure for patch review? — Hongli Lai <hongli@...99.net>
Hi.
[#15855] Ruby 1.8.6 trace return line numbers wrong — "Rocky Bernstein" <rocky.bernstein@...>
Consider this program:
[#15860] Webrick directory traversal exploit on UNIX — Jos Backus <jos@...>
DSecRG Advisory #DSECRG-08-026 aka -018 describes a remote directory traversal
[#15871] Sparc architecture optimizations — Thomas Enebo <Thomas.Enebo@...>
Someone at Sun has been looking at Ruby on Sparc:
Thomas Enebo wrote:
Hello Ruby-core,
Hi,
Yukihiro Matsumoto wrote:
Prashant Srinivasan wrote:
[#15880] Ruby 1.8.6 binding value after "if" expression evaluation — "Rocky Bernstein" <rocky.bernstein@...>
Here's another trace hook weirdness that I've encountered.
Hello,
Thanks. The output you report matches what I get in 1.8.6 and suggests where
I think I've found why this is happening. The trace hook for NODE_IF is
[#15907] Range#member? semantics seem wrong — Dave Thomas <dave@...>
Range#member? has been changed so that it the start and end of the
[#15909] RARRAY_PTR — "Laurent Sansonetti" <laurent.sansonetti@...>
Hi,
[#15917] Ruby 1.9 (trunk) crashes when running RubyGems and Rake — Hongli Lai <hongli@...99.net>
Ruby 1.9 (trunk) seems to crash when running the supplied RubyGems and Rake:
Hi,
Nobuyoshi Nakada wrote:
On Mon, Mar 17, 2008 at 06:53:19PM +0900, Hongli Lai wrote:
[#15927] how to create a block with a block parameter in C? — Paul Brannan <pbrannan@...>
This works in Ruby (1.9):
>>>>> "P" == Paul Brannan <pbrannan@atdesk.com> writes:
[#15933] complex and rational — Dave Thomas <dave@...>
Before I start doing the documentation for the PickAxe, could I just
[#15936] Are Depreciated Methods "add_final" & "remove_final" supposed to ACTUALLY WORK? — Charles Thornton <ceo@...>
In Working on IRHG Docs for GC the following
>>>>> "C" == Charles Thornton <ceo@hawthorne-press.com> writes:
ts wrote:
[#15938] Questions on Enumerator#skip_first and Enumerable#first — "Artem Voroztsov" <artem.voroztsov@...>
I asked in ruby-talk, but did not get answer.
On Mar 18, 2008, at 6:20 AM, Artem Voroztsov wrote:
[#15975] Bugs in REXML — "Federico Builes" <federico.builes@...>
Hi,
On Mar 21, 2008, at 17:35, Federico Builes wrote:
[#15980] 1.8.6 memory leak? — "Stephen Sykes" <sdsykes@...>
Hi,
[#15983] Changing the algorithm of String#* — apeiros <apeiros@...>
Hi there
[#15990] Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...>
Hi,
Hi Dave,
Hi Dave,
Hi,
Hi,
Hi,
On Wed, Mar 26, 2008 at 7:01 PM, Dave Thomas <dave@pragprog.com> wrote:
Dave Thomas wrote:
Dave Thomas wrote:
Dave Thomas wrote:
Dave,
This is all a semantic problem. Different people have different
[#16011] New ERb mode — Marc Haisenko <haisenko@...>
Hi folks,
On Tuesday 25 March 2008, Marc Haisenko wrote:
ERb already does this:
On Tuesday 25 March 2008, Jason Roelofs wrote:
On Tue, Mar 25, 2008 at 11:39 AM, Marc Haisenko <haisenko@comdasys.com> wro=
On Tuesday 25 March 2008, Jason Roelofs wrote:
[#16023] some Enumerable methods slower in 1.9 on OS X after revision 15124 — Chris Shea <cmshea@...>
All,
Hi,
Hi,
On Thu, Mar 27, 2008 at 02:26:51PM +0900, Nobuyoshi Nakada wrote:
Hi,
Nobuyoshi Nakada wrote:
Hi,
[#16057] About the license of gserver.rb being "freeware"? — "XiaoLiang Liu" <liuxlsh@...>
Hello everyone,
[#16088] command_call in parse.y — Adrian Thurston <thurston@...>
Hi,
[PATCH] 1.9 and 1.8.6: Fixnum#gcd(Fixnum) improves performance of Date, Rational.
Can this be added to 1.8.7 and trunk? * numeric.c (gcd): Added Fixnum#gcd(Fixnum) support in C. Date uses Rational heavily, which calls Integer#gcd for every new Rational. The Integer#gcd method is generic to handle Bignums, but performs terribly for Fixnum#gcd(Fixnum), which is probably the most often case. The 1.8.6 patch improves Fixnum#gcd performance by 1000%. The 1.9 patch improves Fixnum#gcd performance by 300%. See http://rubyforge.org/tracker/?func=detail&aid=19034&group_id=426&atid=1698 Thanks, Kurt Stephens http://kurtstephens.com
Attachments (3)
Index: ruby-1.8.6-svn/numeric.c
===================================================================
--- ruby-1.8.6-svn/numeric.c (revision 15827)
+++ ruby-1.8.6-svn/numeric.c (working copy)
@@ -2380,6 +2380,41 @@
}
}
+
+/*
+ * call-seq:
+ * Fixnum.gcd(Integer) => Integer
+ *
+ * Returns the <em>greatest common denominator</em> of the two numbers (+self+
+ * and +n+).
+ *
+ * This is a specialization of <code>Integer#gcd</code> for Fixnum arguments.
+ * See <code>rational.rb</code> for more details.
+ *
+ */
+
+static VALUE
+fix_gcd(int argc, VALUE *argv, VALUE self) {
+ if ( argc != 1 ) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 1);
+ }
+ if ( FIXNUM_P(argv[0]) ) {
+ long a = FIX2LONG(self);
+ long b = FIX2LONG(argv[0]);
+ long min = a < 0 ? - a : a;
+ long max = b < 0 ? - b : b;
+ while ( min > 0 ) {
+ long tmp = min;
+ min = max % min;
+ max = tmp;
+ }
+ return LONG2FIX(max);
+ } else {
+ return rb_call_super(1, argv);
+ }
+}
+
+
/*
* call-seq:
* ~fix => integer
@@ -2904,6 +2939,7 @@
rb_define_method(rb_cFixnum, "modulo", fix_mod, 1);
rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1);
rb_define_method(rb_cFixnum, "quo", fix_quo, 1);
+ rb_define_method(rb_cFixnum, "gcd", fix_gcd, -1);
rb_define_method(rb_cFixnum, "**", fix_pow, 1);
rb_define_method(rb_cFixnum, "abs", fix_abs, 0);
Index: ruby-1.8.6-svn/ChangeLog
===================================================================
--- ruby-1.8.6-svn/ChangeLog (revision 15827)
+++ ruby-1.8.6-svn/ChangeLog (working copy)
@@ -1,3 +1,12 @@
+Sun Mar 24 03:09:01 UTC 2008 Kurt Stephens <ks.ruby@kurtstephens.com>
+
+ * numeric.c (gcd): Added Fixnum#gcd(Fixnum) support in C.
+ Date uses Rational heavily, which calls Integer#gcd for every new
+ Rational. The Integer#gcd method is generic to handle Bignums,
+ but performs terribly for Fixnum#gcd(Fixnum),
+ which is probably the most often case. Improves gcd performance on
+ Fixnums by 1000%.
+
Mon Mar 3 23:34:13 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpservlet/filehandler.rb: should normalize path
Index: ruby-trunk/ChangeLog
===================================================================
--- ruby-trunk/ChangeLog (revision 15827)
+++ ruby-trunk/ChangeLog (working copy)
@@ -1,3 +1,12 @@
+Sun Mar 24 03:09:01 UTC 2008 Kurt Stephens <ks.ruby@kurtstephens.com>
+
+ * numeric.c (gcd): Added Fixnum#gcd(Fixnum) support in C.
+ Date uses Rational heavily, which calls Integer#gcd for every new
+ Rational. The Integer#gcd method is generic to handle Bignums,
+ but performs terribly for Fixnum#gcd(Fixnum),
+ which is probably the most often case. Improves gcd performance on
+ Fixnums by 300%.
+
Sun Mar 23 02:51:57 2008 Tanaka Akira <akr@fsij.org>
* process.c (rlimit_resource_value): use NUM2RLIM.
Index: ruby-trunk/numeric.c
===================================================================
--- ruby-trunk/numeric.c (revision 15827)
+++ ruby-trunk/numeric.c (working copy)
@@ -2377,6 +2377,41 @@
}
}
+
+/*
+ * call-seq:
+ * Fixnum.gcd(Integer) => Integer
+ *
+ * Returns the <em>greatest common denominator</em> of the two numbers (+self+
+ * and +n+).
+ *
+ * This is a specialization of <code>Integer#gcd</code> for Fixnum arguments.
+ * See <code>rational.rb</code> for more details.
+ *
+ */
+
+static VALUE
+fix_gcd(int argc, VALUE *argv, VALUE self) {
+ if ( argc != 1 ) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, 1);
+ }
+ if ( FIXNUM_P(argv[0]) ) {
+ /* fprintf(stderr, "Using Fixnum#gcd(Fixnum)\n"); */
+ long a = FIX2LONG(self);
+ long b = FIX2LONG(argv[0]);
+ long min = a < 0 ? - a : a;
+ long max = b < 0 ? - b : b;
+ while ( min > 0 ) {
+ long tmp = min;
+ min = max % min;
+ max = tmp;
+ }
+ return LONG2FIX(max);
+ } else {
+ return rb_call_super(1, argv);
+ }
+}
+
static VALUE
int_pow(long x, unsigned long y)
{
@@ -3233,6 +3268,7 @@
rb_define_method(rb_cFixnum, "quo", fix_quo, 1);
rb_define_method(rb_cFixnum, "rdiv", fix_quo, 1);
rb_define_method(rb_cFixnum, "fdiv", fix_fdiv, 1);
+ rb_define_method(rb_cFixnum, "gcd", (VALUE(*)(ANYARGS)) fix_gcd, -1);
rb_define_method(rb_cFixnum, "**", fix_pow, 1);
rb_define_method(rb_cFixnum, "abs", fix_abs, 0);
Index: ruby-trunk/test/ruby/test_fixnum.rb
===================================================================
--- ruby-trunk/test/ruby/test_fixnum.rb (revision 15827)
+++ ruby-trunk/test/ruby/test_fixnum.rb (working copy)
@@ -245,4 +245,13 @@
assert_equal(:foo, :foo.to_i.to_sym)
assert_nil(0.to_sym)
end
+
+ def test_gcd
+ assert_equal(0, 0.gcd(0))
+ assert_equal(1, 1.gcd(0))
+ assert_equal(1, 0.gcd(1))
+ assert_equal(5, 5.gcd(10))
+ assert_equal(5, 10.gcd(5))
+ assert_equal(1, 5.gcd(7))
+ end
end