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
b1e0bd4b
Commit
b1e0bd4b
authored
Jul 24, 2010
by
Benjamin Kramer
Browse files
Reduce code duplication
parent
e39c8b50
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dict.c
View file @
b1e0bd4b
...
@@ -651,7 +651,7 @@ static unsigned int _dictStringCopyHTHashFunction(const void *key)
...
@@ -651,7 +651,7 @@ static unsigned int _dictStringCopyHTHashFunction(const void *key)
return
dictGenHashFunction
(
key
,
strlen
(
key
));
return
dictGenHashFunction
(
key
,
strlen
(
key
));
}
}
static
void
*
_dictString
CopyHTKey
Dup
(
void
*
privdata
,
const
void
*
key
)
static
void
*
_dictStringDup
(
void
*
privdata
,
const
void
*
key
)
{
{
int
len
=
strlen
(
key
);
int
len
=
strlen
(
key
);
char
*
copy
=
_dictAlloc
(
len
+
1
);
char
*
copy
=
_dictAlloc
(
len
+
1
);
...
@@ -662,17 +662,6 @@ static void *_dictStringCopyHTKeyDup(void *privdata, const void *key)
...
@@ -662,17 +662,6 @@ static void *_dictStringCopyHTKeyDup(void *privdata, const void *key)
return
copy
;
return
copy
;
}
}
static
void
*
_dictStringKeyValCopyHTValDup
(
void
*
privdata
,
const
void
*
val
)
{
int
len
=
strlen
(
val
);
char
*
copy
=
_dictAlloc
(
len
+
1
);
DICT_NOTUSED
(
privdata
);
memcpy
(
copy
,
val
,
len
);
copy
[
len
]
=
'\0'
;
return
copy
;
}
static
int
_dictStringCopyHTKeyCompare
(
void
*
privdata
,
const
void
*
key1
,
static
int
_dictStringCopyHTKeyCompare
(
void
*
privdata
,
const
void
*
key1
,
const
void
*
key2
)
const
void
*
key2
)
{
{
...
@@ -681,47 +670,40 @@ static int _dictStringCopyHTKeyCompare(void *privdata, const void *key1,
...
@@ -681,47 +670,40 @@ static int _dictStringCopyHTKeyCompare(void *privdata, const void *key1,
return
strcmp
(
key1
,
key2
)
==
0
;
return
strcmp
(
key1
,
key2
)
==
0
;
}
}
static
void
_dictStringCopyHTKeyDestructor
(
void
*
privdata
,
void
*
key
)
static
void
_dictStringDestructor
(
void
*
privdata
,
void
*
key
)
{
DICT_NOTUSED
(
privdata
);
_dictFree
((
void
*
)
key
);
/* ATTENTION: const cast */
}
static
void
_dictStringKeyValCopyHTValDestructor
(
void
*
privdata
,
void
*
val
)
{
{
DICT_NOTUSED
(
privdata
);
DICT_NOTUSED
(
privdata
);
_dictFree
(
(
void
*
)
val
);
/* ATTENTION: const cast */
_dictFree
(
key
);
}
}
dictType
dictTypeHeapStringCopyKey
=
{
dictType
dictTypeHeapStringCopyKey
=
{
_dictStringCopyHTHashFunction
,
/* hash function */
_dictStringCopyHTHashFunction
,
/* hash function */
_dictString
CopyHTKey
Dup
,
/* key dup */
_dictStringDup
,
/* key dup */
NULL
,
/* val dup */
NULL
,
/* val dup */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictString
CopyHTKey
Destructor
,
/* key destructor */
_dictStringDestructor
,
/* key destructor */
NULL
/* val destructor */
NULL
/* val destructor */
};
};
/* This is like StringCopy but does not auto-duplicate the key.
/* This is like StringCopy but does not auto-duplicate the key.
* It's used for intepreter's shared strings. */
* It's used for intepreter's shared strings. */
dictType
dictTypeHeapStrings
=
{
dictType
dictTypeHeapStrings
=
{
_dictStringCopyHTHashFunction
,
/* hash function */
_dictStringCopyHTHashFunction
,
/* hash function */
NULL
,
/* key dup */
NULL
,
/* key dup */
NULL
,
/* val dup */
NULL
,
/* val dup */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictString
CopyHTKey
Destructor
,
/* key destructor */
_dictStringDestructor
,
/* key destructor */
NULL
/* val destructor */
NULL
/* val destructor */
};
};
/* This is like StringCopy but also automatically handle dynamic
/* This is like StringCopy but also automatically handle dynamic
* allocated C strings as values. */
* allocated C strings as values. */
dictType
dictTypeHeapStringCopyKeyValue
=
{
dictType
dictTypeHeapStringCopyKeyValue
=
{
_dictStringCopyHTHashFunction
,
/* hash function */
_dictStringCopyHTHashFunction
,
/* hash function */
_dictString
CopyHTKey
Dup
,
/* key dup */
_dictStringDup
,
/* key dup */
_dictString
KeyValCopyHTValDup
,
/* val dup */
_dictString
Dup
,
/* val dup */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictStringCopyHTKeyCompare
,
/* key compare */
_dictString
CopyHTKey
Destructor
,
/* key destructor */
_dictStringDestructor
,
/* key destructor */
_dictString
KeyValCopyHTVal
Destructor
,
/* val destructor */
_dictStringDestructor
,
/* val destructor */
};
};
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