Skip to content

Instantly share code, notes, and snippets.

View matthewd's full-sized avatar

Matthew Draper matthewd

View GitHub Profile
diff --git a/spec/capi/ext/symbol_spec.c b/spec/capi/ext/symbol_spec.c
new file mode 100644
index 0000000..79f0250
--- /dev/null
+++ b/spec/capi/ext/symbol_spec.c
@@ -0,0 +1,22 @@
+#include "ruby.h"
+
+VALUE symbol_spec_rb_is_const_id(VALUE self, VALUE sym) {
+ return rb_is_const_id(SYM2ID(sym));
diff --git a/kernel/common/module.rb b/kernel/common/module.rb
index fe15498..6399184 100644
--- a/kernel/common/module.rb
+++ b/kernel/common/module.rb
@@ -116,13 +116,13 @@ class Module
end
# Always also search Object (and everything included in Object).
- # This lets a module alias methods on Kernel.
- if instance_of?(Module) and self != Kernel
From 6b204921badcd210a063d7e87a73d186bc30ecc9 Mon Sep 17 00:00:00 2001
From: Matthew Draper <matthew@trebex.net>
Date: Fri, 28 May 2010 00:47:45 +0930
Subject: [PATCH] Remove redundant method lookup functions.
---
kernel/common/module.rb | 58 +++++++-------------------------------
kernel/common/variable_scope.rb | 2 +-
kernel/delta/module.rb | 2 +-
3 files changed, 13 insertions(+), 49 deletions(-)
irb(main):002:0> puts ObjectSpace.each_object(Class).to_a.map {|c| begin; c.allocate; nil; rescue => ex; ex.to_s; end }.compact.sort
allocator undefined for Bignum
allocator undefined for Binding
allocator undefined for Continuation
allocator undefined for Data
allocator undefined for FalseClass
allocator undefined for Fixnum
allocator undefined for Float
allocator undefined for Integer
allocator undefined for Method
From d5708d57aa4653a5cdeb85c6c21c2d1aaae971d5 Mon Sep 17 00:00:00 2001
From: Matthew Draper <matthew@trebex.net>
Date: Sat, 18 Sep 2010 14:49:15 +0930
Subject: [PATCH] Remove unused foot-gun primitive.
---
kernel/bootstrap/fixnum.rb | 5 -----
vm/builtin/bignum.hpp | 1 -
2 files changed, 0 insertions(+), 6 deletions(-)
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "Kernel#sprintf" do
it "is a private method" do
Kernel.should have_private_instance_method(:sprintf)
end
it "treats nil arguments as zero-width strings in %s slots" do
sprintf("%s%d%s%s", nil, 4, 'a', 'b').should == '4ab'
"%*1$.*2$3$d"
0000: push_local 2 # 3$
0002: push_const_fast :Kernel, 1
0005: swap_stack
0006: send_stack :Integer, 1
0009: send_method :to_s
0011: push_const_fast :Kernel, 4
0014: push_local 1 # 2$
0016: send_stack :Integer, 1
0019: dup_top
require 'benchmark'
total = (ENV['TOTAL'] || 1000000).to_i
Benchmark.bmbm do |x|
x.report("'%d'") do
total.times { sprintf('%d', 10) }
end
x.report("'Hello %s, from %4.2f'") do
module Rubinius
class Sprinter
class << self
def get(format)
@cache ||= {}
if format.tainted?
new(format)
else
@cache[format] ||
From 87bf16defc57148ba2014c7b523eda90b59affa1 Mon Sep 17 00:00:00 2001
From: Matthew Draper <matthew@trebex.net>
Date: Mon, 29 Nov 2010 01:30:11 +1030
Subject: [PATCH 1/2] Compile sprintf strings to rbx bytecode.
With appropriate caching, this gets our performance into the same
ballpark as MRI. With perfect caching (code choosing to explicitly
pre-compile an expression once, say), this outperforms MRI.
---
benchmark/rubinius/bm_sprintf.rb | 34 ++