summaryrefslogtreecommitdiff
path: root/test/rdoc
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-08-07 02:14:39 +0900
committeraycabta <aycabta@gmail.com>2019-08-16 06:07:11 +0900
commitf71bd7477e84eb1cd10fa27e79b1e081ee51793a (patch)
tree99f3486dde42fdd28bcbb73ee5f0040538c4e87f /test/rdoc
parentb64911f4e262bef582557f6d11dc5cb35dae669c (diff)
RDoc::Parser::C: Integrate do_classes and do_modules by one regexp match
The full scan of the C source code (`@content.scan`) is very slow. The old code invokes the scan six times in `do_classes` and `do_modules`. This change integrates the six scans into one by merging the regexps. The integrated regexp is a bit hard to maintain, but the speed up is significant: approx. 30 sec -> 20 sec in Ruby's `make rdoc`. In addition, this change omits `do_boot_defclass` unless the file name is `class.c`. `boot_defclass` is too specific to Ruby's source code, so RDoc should handle it as a special case. Before this change: TOTAL (pct) SAMPLES (pct) FRAME 858 (13.6%) 858 (13.6%) (garbage collection) 292 (4.6%) 264 (4.2%) RDoc::Parser::C#do_define_class 263 (4.2%) 250 (3.9%) RDoc::Parser::C#do_define_module 275 (4.3%) 241 (3.8%) RDoc::Parser::C#do_define_class_under 248 (3.9%) 237 (3.7%) RDoc::Parser::C#do_define_module_under 234 (3.7%) 234 (3.7%) RDoc::Parser::C#gen_body_table 219 (3.5%) 219 (3.5%) Ripper::Lexer#state_obj 217 (3.4%) 216 (3.4%) RDoc::Parser::C#do_struct_define_without_accessor 205 (3.2%) 205 (3.2%) RDoc::Parser::C#do_boot_defclass 205 (3.2%) 205 (3.2%) RDoc::Parser::C#do_singleton_class The six methods take approx. 22.2%. `do_define_class` (4.2%) + `do_define_class_under` (3.8%) + `do_define_module` (3,9$) + `do_define_module_under` (3.7%) + `do_struct_define_without_accessor` (3.4%) + `do_singleton_class` (3.2%) After this change, the methods are integrated to `do_classes_and_modules` which takes only 5.8%. TOTAL (pct) SAMPLES (pct) FRAME 812 (16.7%) 812 (16.7%) (garbage collection) 355 (7.3%) 284 (5.8%) RDoc::Parser::C#do_classes_and_modules 225 (4.6%) 225 (4.6%) RDoc::Parser::C#gen_body_table 429 (8.8%) 210 (4.3%) RDoc::Parser::RubyTools#get_tk 208 (4.3%) 208 (4.3%) RDoc::TokenStream#add_tokens
Diffstat (limited to 'test/rdoc')
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb34
1 files changed, 3 insertions, 31 deletions
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index 81727ad759..6601d28f60 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -304,32 +304,6 @@ void Init_Blah(void) {
assert_equal 'This should show up as an alias', methods.last.comment.text
end
- def test_do_classes_boot_class
- content = <<-EOF
-/* Document-class: Foo
- * this is the Foo boot class
- */
-VALUE cFoo = boot_defclass("Foo", rb_cObject);
- EOF
-
- klass = util_get_class content, 'cFoo'
- assert_equal "this is the Foo boot class", klass.comment.text
- assert_equal 'Object', klass.superclass
- end
-
- def test_do_classes_boot_class_nil
- content = <<-EOF
-/* Document-class: Foo
- * this is the Foo boot class
- */
-VALUE cFoo = boot_defclass("Foo", 0);
- EOF
-
- klass = util_get_class content, 'cFoo'
- assert_equal "this is the Foo boot class", klass.comment.text
- assert_nil klass.superclass
- end
-
def test_do_aliases_missing_class
content = <<-EOF
void Init_Blah(void) {
@@ -511,7 +485,7 @@ void Init_foo(){
@parser = util_parser content
- @parser.do_classes
+ @parser.do_classes_and_modules
@parser.do_constants
klass = @parser.classes['cFoo']
@@ -581,8 +555,7 @@ void Init_curses(){
@parser = util_parser content
- @parser.do_modules
- @parser.do_classes
+ @parser.do_classes_and_modules
@parser.do_constants
klass = @parser.classes['mCurses']
@@ -608,8 +581,7 @@ void Init_File(void) {
@parser = util_parser content
- @parser.do_modules
- @parser.do_classes
+ @parser.do_classes_and_modules
@parser.do_constants
klass = @parser.classes['rb_mFConst']