summaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-11 17:46:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-11 17:46:52 +0000
commiteb424f60cd2f4d6a97bdf4ca24a072689d09b05f (patch)
tree641874edebfc4982c6ffac04db4eb5f8a01ee5fe /object.c
parent44b86ef7ec1a9ba6eb65effd44541e4e3ab22ab0 (diff)
downloadruby-eb424f60cd2f4d6a97bdf4ca24a072689d09b05f.tar.gz
ruby-eb424f60cd2f4d6a97bdf4ca24a072689d09b05f.tar.xz
ruby-eb424f60cd2f4d6a97bdf4ca24a072689d09b05f.zip
* range.c (range_include): specialize single character string
case (e.g. (?a ..?z).include(?x)) for performance. [ruby-core:15481] * string.c (rb_str_upto): specialize single character case. * string.c (rb_str_hash): omit coderange scan for performance. * object.c (rb_check_to_integer): check Fixnum first. * object.c (rb_to_integer): ditto. * string.c (rb_str_equal): inline memcmp to avoid unnecessary rb_str_comparable(). * parse.y (rb_intern2): use US-ASCII encoding. * parse.y (rb_intern_str): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/object.c b/object.c
index 7970c5117..dc8c3bb3b 100644
--- a/object.c
+++ b/object.c
@@ -1940,7 +1940,10 @@ rb_check_convert_type(VALUE val, int type, const char *tname, const char *method
static VALUE
rb_to_integer(VALUE val, const char *method)
{
- VALUE v = convert_type(val, "Integer", method, Qtrue);
+ VALUE v;
+
+ if (FIXNUM_P(val)) return val;
+ v = convert_type(val, "Integer", method, Qtrue);
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
char *cname = rb_obj_classname(val);
rb_raise(rb_eTypeError, "can't convert %s to Integer (%s#%s gives %s)",
@@ -1952,7 +1955,10 @@ rb_to_integer(VALUE val, const char *method)
VALUE
rb_check_to_integer(VALUE val, const char *method)
{
- VALUE v = convert_type(val, "Integer", method, Qfalse);
+ VALUE v;
+
+ if (FIXNUM_P(val)) return val;
+ v = convert_type(val, "Integer", method, Qfalse);
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
return Qnil;
}