aboutsummaryrefslogtreecommitdiff
path: root/ruby/ext/google/protobuf_c/protobuf.c
diff options
context:
space:
mode:
authorChris Fallin <cfallin@google.com>2015-05-19 15:33:48 -0700
committerChris Fallin <cfallin@google.com>2015-05-19 16:19:00 -0700
commit231886f6327b7cad480b96d08595f45b3526cb4a (patch)
treea20711cf778f1f0d516d4648991a997963fe24f9 /ruby/ext/google/protobuf_c/protobuf.c
parenta8b38c598d7f65b281a72809b28117afdb760931 (diff)
downloadprotobuf-231886f6327b7cad480b96d08595f45b3526cb4a.tar.gz
protobuf-231886f6327b7cad480b96d08595f45b3526cb4a.tar.bz2
protobuf-231886f6327b7cad480b96d08595f45b3526cb4a.zip
Ruby C extension speedup: don't re-intern constant string needlessly.
Also fixed lines with > 80 char length.
Diffstat (limited to 'ruby/ext/google/protobuf_c/protobuf.c')
-rw-r--r--ruby/ext/google/protobuf_c/protobuf.c10
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");