Skip to content

Commit 4a18352

Browse files
committed
Lazyfree: Hash converted to use plain SDS WIP 3.
1 parent 777396a commit 4a18352

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

src/db.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ void scanCallback(void *privdata, const dictEntry *de) {
418418
sds keysds = dictGetKey(de);
419419
key = createStringObject(keysds,sdslen(keysds));
420420
} else if (o->type == OBJ_HASH) {
421-
key = dictGetKey(de);
422-
incrRefCount(key);
423-
val = dictGetVal(de);
424-
incrRefCount(val);
421+
sds sdskey = dictGetKey(de);
422+
sds sdsval = dictGetVal(de);
423+
key = createStringObject(keysds,sdslen(keysds));
424+
val = createStringObject(valsds,sdslen(valsds));
425425
} else if (o->type == OBJ_ZSET) {
426426
sds keysds = dictGetKey(de);
427427
key = createStringObject(keysds,sdslen(keysds));

src/t_hash.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,6 @@ void hincrbyCommand(client *c) {
545545
server.dirty++;
546546
}
547547

548-
/* XXX From here. */
549-
550548
void hincrbyfloatCommand(client *c) {
551549
double value, incr;
552550
long long ll;
@@ -593,7 +591,9 @@ void hincrbyfloatCommand(client *c) {
593591
decrRefCount(newobj);
594592
}
595593

596-
static void addHashFieldToReply(client *c, robj *o, robj *field) {
594+
/* XXX From here. */
595+
596+
static void addHashFieldToReply(client *c, robj *o, sds field) {
597597
int ret;
598598

599599
if (o == NULL) {
@@ -618,15 +618,11 @@ static void addHashFieldToReply(client *c, robj *o, robj *field) {
618618
}
619619

620620
} else if (o->encoding == OBJ_ENCODING_HT) {
621-
robj *value;
622-
623-
ret = hashTypeGetFromHashTable(o, field, &value);
624-
if (ret < 0) {
621+
sds value = hashTypeGetFromHashTable(o, field);
622+
if (value == NULL)
625623
addReply(c, shared.nullbulk);
626-
} else {
627-
addReplyBulk(c, value);
628-
}
629-
624+
else
625+
addReplyBulkCBuffer(c, value, sdslen(value));
630626
} else {
631627
serverPanic("Unknown hash encoding");
632628
}
@@ -638,7 +634,7 @@ void hgetCommand(client *c) {
638634
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
639635
checkType(c,o,OBJ_HASH)) return;
640636

641-
addHashFieldToReply(c, o, c->argv[2]);
637+
addHashFieldToReply(c, o, c->argv[2]->ptr);
642638
}
643639

644640
void hmgetCommand(client *c) {
@@ -655,7 +651,7 @@ void hmgetCommand(client *c) {
655651

656652
addReplyMultiBulkLen(c, c->argc-2);
657653
for (i = 2; i < c->argc; i++) {
658-
addHashFieldToReply(c, o, c->argv[i]);
654+
addHashFieldToReply(c, o, c->argv[i]->ptr);
659655
}
660656
}
661657

@@ -667,7 +663,7 @@ void hdelCommand(client *c) {
667663
checkType(c,o,OBJ_HASH)) return;
668664

669665
for (j = 2; j < c->argc; j++) {
670-
if (hashTypeDelete(o,c->argv[j])) {
666+
if (hashTypeDelete(o,c->argv[j]->ptr)) {
671667
deleted++;
672668
if (hashTypeLength(o) == 0) {
673669
dbDelete(c->db,c->argv[1]);
@@ -701,7 +697,7 @@ void hstrlenCommand(client *c) {
701697

702698
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
703699
checkType(c,o,OBJ_HASH)) return;
704-
addReplyLongLong(c,hashTypeGetValueLength(o,c->argv[2]));
700+
addReplyLongLong(c,hashTypeGetValueLength(o,c->argv[2]->ptr));
705701
}
706702

707703
static void addHashIteratorCursorToReply(client *c, hashTypeIterator *hi, int what) {
@@ -711,18 +707,13 @@ static void addHashIteratorCursorToReply(client *c, hashTypeIterator *hi, int wh
711707
long long vll = LLONG_MAX;
712708

713709
hashTypeCurrentFromZiplist(hi, what, &vstr, &vlen, &vll);
714-
if (vstr) {
710+
if (vstr)
715711
addReplyBulkCBuffer(c, vstr, vlen);
716-
} else {
712+
else
717713
addReplyBulkLongLong(c, vll);
718-
}
719-
720714
} else if (hi->encoding == OBJ_ENCODING_HT) {
721-
robj *value;
722-
723-
hashTypeCurrentFromHashTable(hi, what, &value);
724-
addReplyBulk(c, value);
725-
715+
sds value = hashTypeCurrentFromHashTable(hi, what);
716+
addReplyBulkCBuffer(c, value, sdslen(value));
726717
} else {
727718
serverPanic("Unknown hash encoding");
728719
}
@@ -776,7 +767,7 @@ void hexistsCommand(client *c) {
776767
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
777768
checkType(c,o,OBJ_HASH)) return;
778769

779-
addReply(c, hashTypeExists(o,c->argv[2]) ? shared.cone : shared.czero);
770+
addReply(c, hashTypeExists(o,c->argv[2]->ptr) ? shared.cone : shared.czero);
780771
}
781772

782773
void hscanCommand(client *c) {

0 commit comments

Comments
 (0)