[Pkg-javascript-commits] [node-leveldown] 392/492: minor cleanups

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:22 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 7cf24772c6b2af941d3850123ea6f9337e060aa6
Author: Rod Vagg <rod at vagg.org>
Date:   Mon Aug 19 22:20:32 2013 +1000

    minor cleanups
---
 src/iterator.cc | 72 +++++++++++++++++++++++++--------------------------------
 src/iterator.h  | 12 +++++-----
 2 files changed, 37 insertions(+), 47 deletions(-)

diff --git a/src/iterator.cc b/src/iterator.cc
index 196ca63..7797791 100644
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@ -23,14 +23,14 @@ Iterator::Iterator (
   , bool keys
   , bool values
   , int limit
-  , bool fillCache
-  , bool keyAsBuffer
-  , bool valueAsBuffer
-  , v8::Local<v8::Object> &startHandle
   , std::string* lt
   , std::string* lte
   , std::string* gt
   , std::string* gte
+  , bool fillCache
+  , bool keyAsBuffer
+  , bool valueAsBuffer
+  , v8::Local<v8::Object> &startHandle
 ) : database(database)
   , id(id)
   , start(start)
@@ -39,12 +39,12 @@ Iterator::Iterator (
   , keys(keys)
   , values(values)
   , limit(limit)
-  , keyAsBuffer(keyAsBuffer)
-  , valueAsBuffer(valueAsBuffer)
   , lt(lt)
   , lte(lte)
   , gt(gt)
   , gte(gte)
+  , keyAsBuffer(keyAsBuffer)
+  , valueAsBuffer(valueAsBuffer)
 {
   NanScope();
 
@@ -62,7 +62,6 @@ Iterator::Iterator (
   endWorker  = NULL;
 };
 
-
 Iterator::~Iterator () {
   delete options;
   if (!persistentHandle.IsEmpty())
@@ -81,43 +80,38 @@ bool Iterator::GetIterator () {
       dbIterator->Seek(*start);
 
       if (reverse) {
-        if (!dbIterator->Valid())
+        if (!dbIterator->Valid()) {
+          // if it's past the last key, step back
           dbIterator->SeekToLast();
-        //if it's past the last key, step back
-        else {
+        } else {
           std::string key_ = dbIterator->key().ToString();
 
-          if(lt != NULL) {
-            if(lt->compare(key_) <= 0)
+          if (lt != NULL) {
+            if (lt->compare(key_) <= 0)
               dbIterator->Prev();
-          }
-          else if(lte != NULL) {
-            if(lte->compare(key_) < 0)
+          } else if (lte != NULL) {
+            if (lte->compare(key_) < 0)
               dbIterator->Prev();
-          }
-          else if(start != NULL) {
-            if(start->compare(key_))
+          } else if (start != NULL) {
+            if (start->compare(key_))
               dbIterator->Prev();
           }
         }
 
-        if(dbIterator->Valid() && lt != NULL) {
-          if(lt->compare(dbIterator->key().ToString()) <= 0)
+        if (dbIterator->Valid() && lt != NULL) {
+          if (lt->compare(dbIterator->key().ToString()) <= 0)
             dbIterator->Prev();
-         
         }
-
-      }
-      else {
+      } else {
         if (dbIterator->Valid() && gt != NULL
-          && gt->compare(dbIterator->key().ToString()) == 0)
+            && gt->compare(dbIterator->key().ToString()) == 0)
           dbIterator->Next();
       }
-    }
-    else if (reverse)
+    } else if (reverse) {
       dbIterator->SeekToLast();
-    else
+    } else {
       dbIterator->SeekToFirst();
+    }
 
     return true;
   }
@@ -125,8 +119,7 @@ bool Iterator::GetIterator () {
 }
 
 bool Iterator::IteratorNext (std::string& key, std::string& value) {
-  //if it's not the first call, move to next item.
-
+  // if it's not the first call, move to next item.
   if (!GetIterator()) {
     if (reverse)
       dbIterator->Prev();
@@ -134,12 +127,12 @@ bool Iterator::IteratorNext (std::string& key, std::string& value) {
       dbIterator->Next();
   }
 
-
+  // now check if this is the end or not, if not then return the key & value
   if (dbIterator->Valid()) {
     std::string key_ = dbIterator->key().ToString();
     int isEnd = end == NULL ? 1 : end->compare(key_);
 
-    if((limit < 0 || ++count <= limit)
+    if ((limit < 0 || ++count <= limit)
       && (end == NULL
           || (reverse && (isEnd <= 0))
           || (!reverse && (isEnd >= 0)))
@@ -155,12 +148,10 @@ bool Iterator::IteratorNext (std::string& key, std::string& value) {
       if (values)
         value.assign(dbIterator->value().data(), dbIterator->value().size());
       return true;
-    } else {
-      return false;
     }
   }
-  else
-    return false;
+
+  return false;
 }
 
 leveldb::Status Iterator::IteratorStatus () {
@@ -185,7 +176,6 @@ void checkEndCallback (Iterator* iterator) {
   }
 }
 
-//void *ctx, void (*callback)(void *ctx, leveldb::Slice key, leveldb::Slice value)
 NAN_METHOD(Iterator::Next) {
   NanScope();
 
@@ -434,14 +424,14 @@ NAN_METHOD(Iterator::New) {
     , keys
     , values
     , limit
-    , fillCache
-    , keyAsBuffer
-    , valueAsBuffer
-    , startHandle
     , lt
     , lte
     , gt
     , gte
+    , fillCache
+    , keyAsBuffer
+    , valueAsBuffer
+    , startHandle
   );
   iterator->Wrap(args.This());
 
diff --git a/src/iterator.h b/src/iterator.h
index 2178132..2d33bcd 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -38,14 +38,14 @@ public:
     , bool keys
     , bool values
     , int limit
-    , bool fillCache
-    , bool keyAsBuffer
-    , bool valueAsBuffer
-    , v8::Local<v8::Object> &startHandle
     , std::string* lt
     , std::string* lte
     , std::string* gt
     , std::string* gte
+    , bool fillCache
+    , bool keyAsBuffer
+    , bool valueAsBuffer
+    , v8::Local<v8::Object> &startHandle
   );
 
   ~Iterator ();
@@ -66,12 +66,12 @@ private:
   bool keys;
   bool values;
   int limit;
-  int count;
   std::string* lt;
   std::string* lte;
   std::string* gt;
   std::string* gte;
-  
+  int count;
+
 public:
   bool keyAsBuffer;
   bool valueAsBuffer;

-- 
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