diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-20 04:18:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-20 04:18:25 +0000 |
commit | 803591e9003482258de5fa695257b0bcd1685710 (patch) | |
tree | 3046636322e5aa0c69f23dd906d0573e9a38a1dc | |
parent | 2ec2878d559391d22d593691971fc3e0d4f8935d (diff) |
* string.c (sym_eql): fail early to gain performance.
* string.c (sym_hash): cache hash value in aux.shared if possible.
* gc.c (rb_obj_id): no need to treat symbols specially.
* lib/fileutils.rb (FileUtils::FileUtils): singleton_methods() no
longer return an array of strings, but of symbols.
* lib/delegate.rb (DelegateClass): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | gc.c | 3 | ||||
-rw-r--r-- | lib/delegate.rb | 6 | ||||
-rw-r--r-- | lib/fileutils.rb | 4 | ||||
-rw-r--r-- | string.c | 46 |
5 files changed, 65 insertions, 9 deletions
@@ -14,6 +14,19 @@ Wed Sep 20 09:25:39 2006 Yukihiro Matsumoto <[email protected]> Adolphs <futzilogik at users dot sourceforge dot net>. [ruby-doc:1223] +Tue Sep 19 00:07:17 2006 Yukihiro Matsumoto <[email protected]> + + * string.c (sym_eql): fail early to gain performance. + + * string.c (sym_hash): cache hash value in aux.shared if possible. + + * gc.c (rb_obj_id): no need to treat symbols specially. + + * lib/fileutils.rb (FileUtils::FileUtils): singleton_methods() no + longer return an array of strings, but of symbols. + + * lib/delegate.rb (DelegateClass): ditto. + Tue Sep 19 00:42:15 2006 Nobuyoshi Nakada <[email protected]> * object.c (rb_obj_ivar_defined, rb_mod_cvar_defined): new methods, @@ -24,7 +37,7 @@ Tue Sep 19 00:42:15 2006 Nobuyoshi Nakada <[email protected]> instance_variable_defined? to check if an instance variable is defined. fixed: [ruby-dev:29554] -Mon Sep 18 00:42:15 2006 Yukihiro Matsumoto <[email protected]> +Mon Sep 18 15:29:21 2006 Yukihiro Matsumoto <[email protected]> * dir.c (dir_s_glob): restore GC protection volatile variable. [ruby-dev:29588] @@ -2037,9 +2037,6 @@ rb_obj_id(VALUE obj) * 24 if 32-bit, double is 8-byte aligned * 40 if 64-bit */ - if (TYPE(obj) == T_SYMBOL) { - return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG; - } if (SPECIAL_CONST_P(obj)) { return LONG2NUM((long)obj); } diff --git a/lib/delegate.rb b/lib/delegate.rb index 165e54a727..a961cbaad3 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -262,9 +262,9 @@ def DelegateClass(superclass) klass = Class.new methods = superclass.public_instance_methods(true) methods -= [ - "__id__", "object_id", "__send__", "__send", "__send!", "respond_to?", "send", "funcall", - "==", "equal?", "initialize", "method_missing", "__getobj__", "__setobj__", - "clone", "dup", "marshal_dump", "marshal_load", + :__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :funcall, + :==, :equal?, :initialize, :method_missing, :__getobj__, :__setobj__, + :clone, :dup, :marshal_dump, :marshal_load, ] klass.module_eval { include Delegator::MethodDelegation diff --git a/lib/fileutils.rb b/lib/fileutils.rb index f551c65cb2..c80a69e554 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1492,8 +1492,8 @@ module FileUtils OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) } end - METHODS = singleton_methods() - %w( private_module_function - commands options have_option? options_of collect_method ) + METHODS = singleton_methods() - [:private_module_function, + :commands, :options, :have_option?, :options_of, :collect_method] # # This module has all methods of FileUtils module, but it outputs messages @@ -535,6 +535,8 @@ void rb_str_associate(VALUE str, VALUE add) { if (STR_ASSOC_P(str)) { + /* sanity check */ + if (OBJ_FROZEN(str)) rb_error_frozen("string"); /* already associated */ rb_ary_concat(RSTRING(str)->as.heap.aux.shared, add); } @@ -554,6 +556,7 @@ VALUE rb_str_associated(VALUE str) { if (STR_ASSOC_P(str)) { + if (OBJ_FROZEN(str)) return Qfalse; return RSTRING(str)->as.heap.aux.shared; } return Qfalse; @@ -4441,6 +4444,47 @@ sym_equal(VALUE sym1, VALUE sym2) } /* + * call-seq: + * sym.eql?(other) => true or false + * + * Two symbols are equal if they are exactly same symbols. + */ + +static VALUE +sym_eql(VALUE sym1, VALUE sym2) +{ + if (sym1 == sym2) return Qtrue; + if (SYMBOL_P(sym2)) return Qfalse; + return rb_str_eql(sym1, sym2); +} + +/* + * call-seq: + * sym.hash => fixnum + * + * Return a hash based on the symbol's length and content. + */ +static VALUE +sym_hash(VALUE sym) +{ + int h; + VALUE hval; + + if (STR_SHARED_P(sym)) { + /* if a symbol has shared value, that's a hash value. */ + return RSTRING(sym)->as.heap.aux.shared; + } + h = rb_str_hash(sym); + hval = INT2FIX(h); + if (!STR_EMBED_P(sym)) { + FL_SET(sym, STR_ASSOC); + RSTRING(sym)->as.heap.aux.shared = hval; + } + return hval; +} + + +/* * call-seq: * sym.to_i => fixnum * @@ -4721,6 +4765,8 @@ Init_String(void) rb_define_singleton_method(rb_cSymbol, "intern", rb_sym_s_intern, 1); rb_define_method(rb_cSymbol, "==", sym_equal, 1); + rb_define_method(rb_cSymbol, "eql?", sym_eql, 1); + rb_define_method(rb_cSymbol, "hash", sym_hash, 0); rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0); rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0); rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0); |