X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/7b22c44ccd24e7b0b3033803e9117a7da27f2fd3..886c9ecb7c0a68299bbc9b09020d14b3293e2f5a:/src/object.c diff --git a/src/object.c b/src/object.c index 9699ea53..c2b89709 100644 --- a/src/object.c +++ b/src/object.c @@ -1,3 +1,33 @@ +/* Redis Object implementation. + * + * Copyright (c) 2009-2012, Salvatore Sanfilippo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Redis nor the names of its contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + #include "redis.h" #include #include @@ -9,18 +39,8 @@ robj *createObject(int type, void *ptr) { o->ptr = ptr; o->refcount = 1; - /* Set the LRU to the current lruclock (minutes resolution). - * We do this regardless of the fact VM is active as LRU is also - * used for the maxmemory directive when Redis is used as cache. - * - * Note that this code may run in the context of an I/O thread - * and accessing server.lruclock in theory is an error - * (no locks). But in practice this is safe, and even if we read - * garbage Redis will not fail. */ + /* Set the LRU to the current lruclock (minutes resolution). */ o->lru = server.lruclock; - /* The following is only needed if VM is active, but since the conditional - * is probably more costly than initializing the field it's better to - * have every field properly initialized anyway. */ return o; } @@ -48,7 +68,7 @@ robj *createStringObjectFromLongLong(long long value) { /* Note: this function is defined into object.c since here it is where it * belongs but it is actually designed to be used just for INCRBYFLOAT */ robj *createStringObjectFromLongDouble(long double value) { - char buf[256], *p; + char buf[256]; int len; /* We use 17 digits precision since with 128 bit floats that precision @@ -58,8 +78,8 @@ robj *createStringObjectFromLongDouble(long double value) { * a string are exactly the same as what the user typed.) */ len = snprintf(buf,sizeof(buf),"%.17Lf", value); /* Now remove trailing zeroes after the '.' */ - if ((p = strchr(buf,'.')) != NULL) { - p = buf+len-1; + if (strchr(buf,'.') != NULL) { + char *p = buf+len-1; while(*p == '0') { p--; len--; @@ -270,9 +290,7 @@ robj *tryObjectEncoding(robj *o) { /* Ok, this object can be encoded... * - * Can I use a shared object? Only if the object is inside a given - * range and if the back end in use is in-memory. For disk store every - * object in memory used as value should be independent. + * Can I use a shared object? Only if the object is inside a given range * * Note that we also avoid using shared integers when maxmemory is used * because every object needs to have a private LRU field for the LRU