[Pkg-javascript-commits] [node-leveldown] 112/492: minor performance tweaks
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:50 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 320845d0df66efc45034e35f2f43d2b70dd43e36
Author: Rod Vagg <rod at vagg.org>
Date: Sun Dec 16 12:48:26 2012 +1100
minor performance tweaks
---
lib/levelup.js | 12 ++++++------
lib/util.js | 5 +----
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/lib/levelup.js b/lib/levelup.js
index 9f794dc..2a8f7a0 100644
--- a/lib/levelup.js
+++ b/lib/levelup.js
@@ -147,9 +147,9 @@ LevelUP.prototype = {
}
, put: function (key_, value_, options_, callback_) {
- var callback, options, err, key, value
+ var open, callback, options, err, key, value
- if (!this.isOpen() && !this.isClosed()) {
+ if (!(open = this.isOpen()) && !this.isClosed()) {
// limbo, defer the operation
return this.once('ready', function () {
this.put(key_, value_, options_, callback_)
@@ -158,7 +158,7 @@ LevelUP.prototype = {
callback = getCallback(options_, callback_)
- if (this.isOpen()) {
+ if (open) {
options = getOptions(options_, this._options)
key = toBuffer(key_, options.keyEncoding || options.encoding)
value = toBuffer(value_, options.valueEncoding || options.encoding)
@@ -182,9 +182,9 @@ LevelUP.prototype = {
}
, del: function (key_, options_, callback_) {
- var callback, options, err, key
+ var open, callback, options, err, key
- if (!this.isOpen() && !this.isClosed()) {
+ if (!(open = this.isOpen()) && !this.isClosed()) {
// limbo, defer the operation
return this.once('ready', function () {
this.del(key_, options_, callback_)
@@ -193,7 +193,7 @@ LevelUP.prototype = {
callback = getCallback(options_, callback_)
- if (this.isOpen()) {
+ if (open) {
options = getOptions(options_, this._options)
key = toBuffer(key_, options.keyEncoding || options.encoding)
this._db.del(key, options, function (err) {
diff --git a/lib/util.js b/lib/util.js
index c34a084..39ee7a7 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -1,10 +1,7 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
var toBuffer = function (data, encoding) {
- if (encoding == 'json') {
- data = JSON.stringify(data)
- encoding = 'utf8'
- }
+ if (encoding == 'json') return JSON.stringify(data)
if (data === undefined || data === null || Buffer.isBuffer(data)) return data
data = String(data)
return encoding == 'utf8' ? data : new Buffer(data, encoding)
--
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