diff options
Diffstat (limited to 'ruby/ext/google/protobuf_c/protobuf.c')
-rw-r--r-- | ruby/ext/google/protobuf_c/protobuf.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index 8ab518a5..d0625a10 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -64,6 +64,15 @@ rb_encoding* kRubyStringUtf8Encoding; rb_encoding* kRubyStringASCIIEncoding; rb_encoding* kRubyString8bitEncoding; +// Ruby-interned string: "descriptor". We use this identifier to store an +// instance variable on message classes we create in order to link them back to +// their descriptors. +// +// We intern this once at module load time then use the interned identifier at +// runtime in order to avoid the cost of repeatedly interning in hot paths. +const char* kDescriptorInstanceVar = "descriptor"; +ID descriptor_instancevar_interned; + // ----------------------------------------------------------------------------- // Initialization/entry point. // ----------------------------------------------------------------------------- @@ -71,6 +80,7 @@ rb_encoding* kRubyString8bitEncoding; // This must be named "Init_protobuf_c" because the Ruby module is named // "protobuf_c" -- the VM looks for this symbol in our .so. void Init_protobuf_c() { + descriptor_instancevar_interned = rb_intern(kDescriptorInstanceVar); VALUE google = rb_define_module("Google"); VALUE protobuf = rb_define_module_under(google, "Protobuf"); VALUE internal = rb_define_module_under(protobuf, "Internal"); |