summaryrefslogtreecommitdiff
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
commit0472db84c5e2b3e4e8f253cb304d5360de2a6a4a (patch)
tree641874edebfc4982c6ffac04db4eb5f8a01ee5fe /object.c
parent9d968bc2219318ea4f8bd2df877f026c9625a2df (diff)
* 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: svn+ssh://ci.ruby-lang.org/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 7970c51171..dc8c3bb3b4 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;
}