Permalink
Browse files

automatically determine the length of the passed in string

  • Loading branch information...
1 parent 7b572d8 commit 7d7898b0790920f0c8add54c694b379d4c638b70 @igrigorik committed Mar 27, 2011
Showing with 9 additions and 8 deletions.
  1. +9 −8 ext/libsnappy.cc
View
@@ -5,20 +5,21 @@ using namespace snappy;
typedef VALUE (ruby_method)(...);
-extern "C" VALUE compress(VALUE self, VALUE input, VALUE length) {
+extern "C" VALUE compress(VALUE self, VALUE input) {
string *out = new string();
- char *in = StringValuePtr(input);
- size_t sz = snappy::Compress(in, NUM2INT(length), out);
+
+ size_t sz = snappy::Compress(RSTRING_PTR(input), RSTRING_LEN(input), out);
VALUE ret = rb_str_new(out->c_str(), sz);
delete out;
+
return ret;
}
-extern "C" VALUE uncompress(VALUE self, VALUE input, VALUE length) {
+extern "C" VALUE uncompress(VALUE self, VALUE input) {
VALUE ret;
string *out = new string();
- char* str = StringValuePtr(input);
- bool pass = snappy::Uncompress(str, NUM2INT(length), out);
+
+ bool pass = snappy::Uncompress(RSTRING_PTR(input), RSTRING_LEN(input), out);
if (pass)
ret = rb_str_new(out->c_str(), out->length());
@@ -34,6 +35,6 @@ static VALUE RSnappy;
extern "C" void Init_libsnappy()
{
RSnappy = rb_define_class("Snappy", rb_cObject);
- rb_define_singleton_method(RSnappy, "compress", (ruby_method*) &compress, 2);
- rb_define_singleton_method(RSnappy, "uncompress", (ruby_method*) &uncompress, 2);
+ rb_define_singleton_method(RSnappy, "compress", (ruby_method*) &compress, 1);
+ rb_define_singleton_method(RSnappy, "uncompress", (ruby_method*) &uncompress, 1);
}

0 comments on commit 7d7898b

Please sign in to comment.