summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-08-07 13:11:59 -0400
committerTakashi Kokubun <takashikkbn@gmail.com>2023-08-16 17:47:32 -0700
commit9b952670bb4945ea227a72dd9b74ef5972a69757 (patch)
treee858e78afaea4526da86830d09c220528d4a214a
parent96aebb42652c8a2dde0e33d45316da64d26be566 (diff)
[ruby/yarp] Less const_get
Right now whenever you go to create a Ruby object from a C struct we dynamically look up the constants. This is not great for performance. Now instead we template out a constant for each VALUE that holds the classes, and then directly reference it. https://github.com/ruby/yarp/commit/f4756cda77
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8226
-rw-r--r--yarp/extension.c5
-rw-r--r--yarp/extension.h1
2 files changed, 5 insertions, 1 deletions
diff --git a/yarp/extension.c b/yarp/extension.c
index e6ef3f7648..2aa4dca396 100644
--- a/yarp/extension.c
+++ b/yarp/extension.c
@@ -4,6 +4,7 @@
// All non-trivial logic should be in librubyparser so it can be shared its the various callers.
VALUE rb_cYARP;
+VALUE rb_cYARPNode;
VALUE rb_cYARPSource;
VALUE rb_cYARPToken;
VALUE rb_cYARPLocation;
@@ -490,6 +491,7 @@ Init_yarp(void) {
// Grab up references to all of the constants that we're going to need to
// reference throughout this extension.
rb_cYARP = rb_define_module("YARP");
+ rb_cYARPNode = rb_define_class_under(rb_cYARP, "Node", rb_cObject);
rb_cYARPSource = rb_define_class_under(rb_cYARP, "Source", rb_cObject);
rb_cYARPToken = rb_define_class_under(rb_cYARP, "Token", rb_cObject);
rb_cYARPLocation = rb_define_class_under(rb_cYARP, "Location", rb_cObject);
@@ -520,6 +522,7 @@ Init_yarp(void) {
rb_define_singleton_method(rb_cYARPDebug, "memsize", memsize, 1);
rb_define_singleton_method(rb_cYARPDebug, "profile_file", profile_file, 1);
- // Next, initialize the pack API.
+ // Next, initialize the other APIs.
+ Init_yarp_api_node();
Init_yarp_pack();
}
diff --git a/yarp/extension.h b/yarp/extension.h
index 1f281240c2..c8f950c2d2 100644
--- a/yarp/extension.h
+++ b/yarp/extension.h
@@ -11,6 +11,7 @@ VALUE yp_source_new(yp_parser_t *parser);
VALUE yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source);
VALUE yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding);
+void Init_yarp_api_node(void);
void Init_yarp_pack(void);
YP_EXPORTED_FUNCTION void Init_yarp(void);