Permalink
Browse files

intern "localhost" string

Change-Id: I05d5c7bf2a9e3688283bca0d284933dbc74d7f75
Reviewed-on: http://review.couchbase.org/23444
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
funny-falcon authored and avsej committed Dec 19, 2012
1 parent 92b6da4 commit af3b7d959d3becbeba57d659ae4d9cc31e917075
Showing with 19 additions and 7 deletions.
  1. +1 −1 ext/couchbase_ext/bucket.c
  2. +17 −6 ext/couchbase_ext/couchbase_ext.c
  3. +1 −0 ext/couchbase_ext/couchbase_ext.h
@@ -408,7 +408,7 @@ cb_bucket_init(int argc, VALUE *argv, VALUE self)
bucket->self = self;
bucket->exception = Qnil;
bucket->type = LCB_TYPE_BUCKET;
- bucket->hostname = rb_str_new2("localhost");
+ bucket->hostname = cb_vStrLocalhost;
bucket->port = 8091;
bucket->pool = cb_vStrDefault;
bucket->bucket = cb_vStrDefault;
@@ -170,11 +170,23 @@ VALUE cb_eBadHandleError; /* LCB_EBADHANDLE = 0x1c */
/* Default Strings */
VALUE cb_vStrDefault;
VALUE cb_vStrEmpty;
+VALUE cb_vStrLocalhost;
+
+ static VALUE
+cb_intern_string(VALUE ar, const char *str)
+{
+ VALUE tmp = STR_NEW_CSTR(str);
+ rb_str_freeze(tmp);
+ rb_ary_push(ar, tmp);
+ return tmp;
+}
/* Ruby Extension initializer */
void
Init_couchbase_ext(void)
{
+ VALUE interned;
+
cb_mMultiJson = rb_const_get(rb_cObject, rb_intern("MultiJson"));
cb_mURI = rb_const_get(rb_cObject, rb_intern("URI"));
cb_mMarshal = rb_const_get(rb_cObject, rb_intern("Marshal"));
@@ -1079,10 +1091,9 @@ Init_couchbase_ext(void)
cb_sym_version = ID2SYM(rb_intern("version"));
cb_sym_view = ID2SYM(rb_intern("view"));
- cb_vStrDefault = STR_NEW_CSTR("default");
- rb_str_freeze(cb_vStrDefault);
- rb_const_set(cb_mCouchbase, rb_intern("_STR_DEFAULT"), cb_vStrDefault);
- cb_vStrEmpty = STR_NEW_CSTR("");
- rb_str_freeze(cb_vStrEmpty);
- rb_const_set(cb_mCouchbase, rb_intern("_STR_EMPTY"), cb_vStrEmpty);
+ interned = rb_ary_new();
+ rb_const_set(cb_mCouchbase, rb_intern("_INTERNED"), interned);
+ cb_vStrDefault = cb_intern_string(interned, "default");
+ cb_vStrEmpty = cb_intern_string(interned, "");
+ cb_vStrLocalhost = cb_intern_string(interned, "localhost");
}
@@ -303,6 +303,7 @@ extern VALUE cb_eBadHandleError; /* LCB_EBADHANDLE = 0x1c */
/* Default Strings */
extern VALUE cb_vStrDefault;
extern VALUE cb_vStrEmpty;
+extern VALUE cb_vStrLocalhost;
void cb_strip_key_prefix(struct cb_bucket_st *bucket, VALUE key);
VALUE cb_check_error(lcb_error_t rc, const char *msg, VALUE key);

0 comments on commit af3b7d9

Please sign in to comment.