Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d8830200
Unverified
Commit
d8830200
authored
Feb 27, 2018
by
Salvatore Sanfilippo
Committed by
GitHub
Feb 27, 2018
Browse files
Merge pull request #3828 from oranagra/sdsnewlen_pr
add SDS_NOINIT option to sdsnewlen to avoid unnecessary memsets.
parents
813960db
f86df924
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
d8830200
...
@@ -759,7 +759,7 @@ int loadAppendOnlyFile(char *filename) {
...
@@ -759,7 +759,7 @@ int loadAppendOnlyFile(char *filename) {
}
}
if
(
buf
[
0
]
!=
'$'
)
goto
fmterr
;
if
(
buf
[
0
]
!=
'$'
)
goto
fmterr
;
len
=
strtol
(
buf
+
1
,
NULL
,
10
);
len
=
strtol
(
buf
+
1
,
NULL
,
10
);
argsds
=
sdsnewlen
(
NULL
,
len
);
argsds
=
sdsnewlen
(
SDS_NOINIT
,
len
);
if
(
len
&&
fread
(
argsds
,
len
,
1
,
fp
)
==
0
)
{
if
(
len
&&
fread
(
argsds
,
len
,
1
,
fp
)
==
0
)
{
sdsfree
(
argsds
);
sdsfree
(
argsds
);
fakeClient
->
argc
=
j
;
/* Free up to j-1. */
fakeClient
->
argc
=
j
;
/* Free up to j-1. */
...
...
src/networking.c
View file @
d8830200
...
@@ -1306,7 +1306,7 @@ int processMultibulkBuffer(client *c) {
...
@@ -1306,7 +1306,7 @@ int processMultibulkBuffer(client *c) {
sdsIncrLen
(
c
->
querybuf
,
-
2
);
/* remove CRLF */
sdsIncrLen
(
c
->
querybuf
,
-
2
);
/* remove CRLF */
/* Assume that if we saw a fat argument we'll see another one
/* Assume that if we saw a fat argument we'll see another one
* likely... */
* likely... */
c
->
querybuf
=
sdsnewlen
(
NULL
,
c
->
bulklen
+
2
);
c
->
querybuf
=
sdsnewlen
(
SDS_NOINIT
,
c
->
bulklen
+
2
);
sdsclear
(
c
->
querybuf
);
sdsclear
(
c
->
querybuf
);
pos
=
0
;
pos
=
0
;
}
else
{
}
else
{
...
@@ -1585,7 +1585,7 @@ sds getAllClientsInfoString(void) {
...
@@ -1585,7 +1585,7 @@ sds getAllClientsInfoString(void) {
listNode
*
ln
;
listNode
*
ln
;
listIter
li
;
listIter
li
;
client
*
client
;
client
*
client
;
sds
o
=
sdsnewlen
(
NULL
,
200
*
listLength
(
server
.
clients
));
sds
o
=
sdsnewlen
(
SDS_NOINIT
,
200
*
listLength
(
server
.
clients
));
sdsclear
(
o
);
sdsclear
(
o
);
listRewind
(
server
.
clients
,
&
li
);
listRewind
(
server
.
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
...
...
src/object.c
View file @
d8830200
...
@@ -98,7 +98,9 @@ robj *createEmbeddedStringObject(const char *ptr, size_t len) {
...
@@ -98,7 +98,9 @@ robj *createEmbeddedStringObject(const char *ptr, size_t len) {
sh
->
len
=
len
;
sh
->
len
=
len
;
sh
->
alloc
=
len
;
sh
->
alloc
=
len
;
sh
->
flags
=
SDS_TYPE_8
;
sh
->
flags
=
SDS_TYPE_8
;
if
(
ptr
)
{
if
(
ptr
==
SDS_NOINIT
)
sh
->
buf
[
len
]
=
'\0'
;
else
if
(
ptr
)
{
memcpy
(
sh
->
buf
,
ptr
,
len
);
memcpy
(
sh
->
buf
,
ptr
,
len
);
sh
->
buf
[
len
]
=
'\0'
;
sh
->
buf
[
len
]
=
'\0'
;
}
else
{
}
else
{
...
...
src/rdb.c
View file @
d8830200
...
@@ -255,7 +255,7 @@ void *rdbLoadIntegerObject(rio *rdb, int enctype, int flags, size_t *lenptr) {
...
@@ -255,7 +255,7 @@ void *rdbLoadIntegerObject(rio *rdb, int enctype, int flags, size_t *lenptr) {
char
buf
[
LONG_STR_SIZE
],
*
p
;
char
buf
[
LONG_STR_SIZE
],
*
p
;
int
len
=
ll2string
(
buf
,
sizeof
(
buf
),
val
);
int
len
=
ll2string
(
buf
,
sizeof
(
buf
),
val
);
if
(
lenptr
)
*
lenptr
=
len
;
if
(
lenptr
)
*
lenptr
=
len
;
p
=
plain
?
zmalloc
(
len
)
:
sdsnewlen
(
NULL
,
len
);
p
=
plain
?
zmalloc
(
len
)
:
sdsnewlen
(
SDS_NOINIT
,
len
);
memcpy
(
p
,
buf
,
len
);
memcpy
(
p
,
buf
,
len
);
return
p
;
return
p
;
}
else
if
(
encode
)
{
}
else
if
(
encode
)
{
...
@@ -344,10 +344,10 @@ void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) {
...
@@ -344,10 +344,10 @@ void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) {
/* Allocate our target according to the uncompressed size. */
/* Allocate our target according to the uncompressed size. */
if
(
plain
)
{
if
(
plain
)
{
val
=
zmalloc
(
len
);
val
=
zmalloc
(
len
);
if
(
lenptr
)
*
lenptr
=
len
;
}
else
{
}
else
{
val
=
sdsnewlen
(
NULL
,
len
);
val
=
sdsnewlen
(
SDS_NOINIT
,
len
);
}
}
if
(
lenptr
)
*
lenptr
=
len
;
/* Load the compressed representation and uncompress it to target. */
/* Load the compressed representation and uncompress it to target. */
if
(
rioRead
(
rdb
,
c
,
clen
)
==
0
)
goto
err
;
if
(
rioRead
(
rdb
,
c
,
clen
)
==
0
)
goto
err
;
...
@@ -472,7 +472,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
...
@@ -472,7 +472,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
if
(
len
==
RDB_LENERR
)
return
NULL
;
if
(
len
==
RDB_LENERR
)
return
NULL
;
if
(
plain
||
sds
)
{
if
(
plain
||
sds
)
{
void
*
buf
=
plain
?
zmalloc
(
len
)
:
sdsnewlen
(
NULL
,
len
);
void
*
buf
=
plain
?
zmalloc
(
len
)
:
sdsnewlen
(
SDS_NOINIT
,
len
);
if
(
lenptr
)
*
lenptr
=
len
;
if
(
lenptr
)
*
lenptr
=
len
;
if
(
len
&&
rioRead
(
rdb
,
buf
,
len
)
==
0
)
{
if
(
len
&&
rioRead
(
rdb
,
buf
,
len
)
==
0
)
{
if
(
plain
)
if
(
plain
)
...
@@ -483,8 +483,8 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
...
@@ -483,8 +483,8 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
}
}
return
buf
;
return
buf
;
}
else
{
}
else
{
robj
*
o
=
encode
?
createStringObject
(
NULL
,
len
)
:
robj
*
o
=
encode
?
createStringObject
(
SDS_NOINIT
,
len
)
:
createRawStringObject
(
NULL
,
len
);
createRawStringObject
(
SDS_NOINIT
,
len
);
if
(
len
&&
rioRead
(
rdb
,
o
->
ptr
,
len
)
==
0
)
{
if
(
len
&&
rioRead
(
rdb
,
o
->
ptr
,
len
)
==
0
)
{
decrRefCount
(
o
);
decrRefCount
(
o
);
return
NULL
;
return
NULL
;
...
...
src/sds.c
View file @
d8830200
...
@@ -39,6 +39,8 @@
...
@@ -39,6 +39,8 @@
#include "sds.h"
#include "sds.h"
#include "sdsalloc.h"
#include "sdsalloc.h"
const
char
*
SDS_NOINIT
=
"SDS_NOINIT"
;
static
inline
int
sdsHdrSize
(
char
type
)
{
static
inline
int
sdsHdrSize
(
char
type
)
{
switch
(
type
&
SDS_TYPE_MASK
)
{
switch
(
type
&
SDS_TYPE_MASK
)
{
case
SDS_TYPE_5
:
case
SDS_TYPE_5
:
...
@@ -72,6 +74,7 @@ static inline char sdsReqType(size_t string_size) {
...
@@ -72,6 +74,7 @@ static inline char sdsReqType(size_t string_size) {
/* Create a new sds string with the content specified by the 'init' pointer
/* Create a new sds string with the content specified by the 'init' pointer
* and 'initlen'.
* and 'initlen'.
* If NULL is used for 'init' the string is initialized with zero bytes.
* If NULL is used for 'init' the string is initialized with zero bytes.
* If SDS_NOINIT is used, the buffer is left uninitialized;
*
*
* The string is always null-termined (all the sds strings are, always) so
* The string is always null-termined (all the sds strings are, always) so
* even if you create an sds string with:
* even if you create an sds string with:
...
@@ -92,7 +95,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
...
@@ -92,7 +95,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
unsigned
char
*
fp
;
/* flags pointer. */
unsigned
char
*
fp
;
/* flags pointer. */
sh
=
s_malloc
(
hdrlen
+
initlen
+
1
);
sh
=
s_malloc
(
hdrlen
+
initlen
+
1
);
if
(
!
init
)
if
(
init
==
SDS_NOINIT
)
init
=
NULL
;
else
if
(
!
init
)
memset
(
sh
,
0
,
hdrlen
+
initlen
+
1
);
memset
(
sh
,
0
,
hdrlen
+
initlen
+
1
);
if
(
sh
==
NULL
)
return
NULL
;
if
(
sh
==
NULL
)
return
NULL
;
s
=
(
char
*
)
sh
+
hdrlen
;
s
=
(
char
*
)
sh
+
hdrlen
;
...
...
src/sds.h
View file @
d8830200
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#define __SDS_H
#define __SDS_H
#define SDS_MAX_PREALLOC (1024*1024)
#define SDS_MAX_PREALLOC (1024*1024)
const
char
*
SDS_NOINIT
;
#include <sys/types.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdarg.h>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment