]> git.wincent.com - wikitext.git/commitdiff
Remove repetition of ID2SYM() and rb_intern()
authorWincent Colaiuta <win@wincent.com>
Thu, 6 Aug 2009 12:14:21 +0000 (14:14 +0200)
committerWincent Colaiuta <win@wincent.com>
Thu, 6 Aug 2009 12:14:21 +0000 (14:14 +0200)
Use a couple of temporary variables to avoid the ugly repeated calls to
ID2SYM() and rb_intern() with exactly the same parameters each time.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
ext/parser.c

index 52c08895dd4d9fc7f76c24cd48f2f6252366cfa2..29f12cc397ee4c4e1f9b5a18b000b1a96bfc5bae 100644 (file)
@@ -1046,9 +1046,11 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
     if (!NIL_P(options) && TYPE(options) == T_HASH)
     {
         // :indent => 0 (or more)
-        if (rb_funcall(options, rb_intern("has_key?"), 1, ID2SYM(rb_intern("indent"))) == Qtrue)
+        ID has_key = rb_intern("has_key?");
+        ID id = ID2SYM(rb_intern("indent"));
+        if (rb_funcall(options, has_key, 1, id) == Qtrue)
         {
-            VALUE indent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
+            VALUE indent = rb_hash_aref(options, id);
             if (indent == Qfalse)
                 base_indent = -1; // indentation disabled
             else
@@ -1060,13 +1062,14 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
         }
 
         // :base_heading_level => 0/1/2/3/4/5/6
-        if (rb_funcall(options, rb_intern("has_key?"), 1, ID2SYM(rb_intern("base_heading_level"))) == Qtrue)
-            base_heading_level = NUM2INT(rb_hash_aref(options, ID2SYM(rb_intern("base_heading_level"))));
+        id = ID2SYM(rb_intern("base_heading_level"));
+        if (rb_funcall(options, has_key, 1, id) == Qtrue)
+            base_heading_level = NUM2INT(rb_hash_aref(options, id));
 
         // :link_proc => lambda { |link_target| ... }
-        // TODO: refactor to avoid some repeated calls to ID2SYM and rb_intern
-        if (rb_funcall(options, rb_intern("has_key?"), 1, ID2SYM(rb_intern("link_proc"))) == Qtrue)
-            link_proc = rb_hash_aref(options, ID2SYM(rb_intern("link_proc")));
+        id = ID2SYM(rb_intern("link_proc"));
+        if (rb_funcall(options, has_key, 1, id) == Qtrue)
+            link_proc = rb_hash_aref(options, id);
     }
 
     // normalize, regardless of whether this came from instance variable or override