[Pkg-javascript-commits] [node-leveldown] 306/492: compactify LD_STRING_OR_BUFFER_LENGTH

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:11 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit c16ba198997324340db83ee08b9a38553902e94c
Author: Rod Vagg <rod at vagg.org>
Date:   Mon Apr 8 09:34:08 2013 +1000

    compactify LD_STRING_OR_BUFFER_LENGTH
---
 src/iterator.cc |  9 ++++-----
 src/leveldown.h | 10 ++++------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/iterator.cc b/src/iterator.cc
index a58c73f..870294a 100644
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@ -242,7 +242,6 @@ v8::Handle<v8::Value> Iterator::New (const v8::Arguments& args) {
 
   v8::Local<v8::Value> startBuffer;
   leveldb::Slice* start = NULL;
-  size_t length;
   std::string* end = NULL;
   int limit = -1;
 
@@ -258,9 +257,9 @@ v8::Handle<v8::Value> Iterator::New (const v8::Arguments& args) {
           || optionsObj->Get(option_start)->IsString())) {
 
       startBuffer = v8::Local<v8::Value>::New(optionsObj->Get(option_start));
-      LD_STRING_OR_BUFFER_LENGTH(startBuffer, length)
+
       // ignore start if it has size 0 since a Slice can't have length 0
-      if (length > 0) {
+      if (LD_STRING_OR_BUFFER_LENGTH(startBuffer) > 0) {
         LD_STRING_OR_BUFFER_TO_SLICE(_start, startBuffer, start)
         start = new leveldb::Slice(_start.data(), _start.size());
       }
@@ -272,9 +271,9 @@ v8::Handle<v8::Value> Iterator::New (const v8::Arguments& args) {
 
       v8::Local<v8::Value> endBuffer =
           v8::Local<v8::Value>::New(optionsObj->Get(option_end));
-      LD_STRING_OR_BUFFER_LENGTH(endBuffer, length)
+
       // ignore end if it has size 0 since a Slice can't have length 0
-      if (length > 0) {
+      if (LD_STRING_OR_BUFFER_LENGTH(endBuffer) > 0) {
         LD_STRING_OR_BUFFER_TO_SLICE(_end, endBuffer, end)
         end = new std::string(_end.data(), _end.size());
       }
diff --git a/src/leveldown.h b/src/leveldown.h
index e144007..85f99fe 100644
--- a/src/leveldown.h
+++ b/src/leveldown.h
@@ -60,12 +60,10 @@
   } \
   leveldb::Slice to(to ## Ch_, to ## Sz_);
 
-#define LD_STRING_OR_BUFFER_LENGTH(from, length) \
-  if (node::Buffer::HasInstance(from->ToObject())) { \
-    length = node::Buffer::Length(from->ToObject()); \
-  } else { \
-    length = from->ToString()->Utf8Length(); \
-  }
+#define LD_STRING_OR_BUFFER_LENGTH(obj) \
+  node::Buffer::HasInstance(obj->ToObject()) \
+    ? node::Buffer::Length(obj->ToObject()) \
+    : obj->ToString()->Utf8Length()
 
 #define LD_BOOLEAN_OPTION_VALUE(optionsObj, opt) \
   bool opt = !optionsObj.IsEmpty() \

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list