summaryrefslogtreecommitdiff
path: root/storage/innobase/include/mem0mem.h
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-09-04 13:13:59 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-09-05 08:54:36 +0300
commitfe47aee3bd11ffefaea6f020b4f6713703f90129 (patch)
tree807780ee6252b298a29a733d4dcdd2a69d11b999 /storage/innobase/include/mem0mem.h
parent83f9422f0555b6ea7976297a33533924efd244ae (diff)
downloadmariadb-git-fe47aee3bd11ffefaea6f020b4f6713703f90129.tar.gz
Inline definition of mem_heap_dup(), mem_heap_strdup(), mem_heap_strdupl()
Diffstat (limited to 'storage/innobase/include/mem0mem.h')
-rw-r--r--storage/innobase/include/mem0mem.h54
1 files changed, 30 insertions, 24 deletions
diff --git a/storage/innobase/include/mem0mem.h b/storage/innobase/include/mem0mem.h
index e44f3f730af..a4848a4ed69 100644
--- a/storage/innobase/include/mem0mem.h
+++ b/storage/innobase/include/mem0mem.h
@@ -294,26 +294,42 @@ mem_strdupl(
const char* str, /*!< in: string to be copied */
ulint len); /*!< in: length of str, in bytes */
-/** Duplicates a NUL-terminated string, allocated from a memory heap.
+/** Duplicate a block of data, allocated from a memory heap.
+@param[in] heap memory heap where string is allocated
+@param[in] data block of data to be copied
+@param[in] len length of data, in bytes
+@return own: a copy of data */
+inline
+void*
+mem_heap_dup(mem_heap_t* heap, const void* data, size_t len)
+{
+ return(memcpy(mem_heap_alloc(heap, len), data, len));
+}
+
+/** Duplicate a NUL-terminated string, allocated from a memory heap.
@param[in] heap memory heap where string is allocated
@param[in] str string to be copied
@return own: a copy of the string */
+inline
char*
-mem_heap_strdup(
- mem_heap_t* heap,
- const char* str);
+mem_heap_strdup(mem_heap_t* heap, const char* str)
+{
+ return(static_cast<char*>(mem_heap_dup(heap, str, strlen(str) + 1)));
+}
-/**********************************************************************//**
-Makes a NUL-terminated copy of a nonterminated string,
-allocated from a memory heap.
-@return own: a copy of the string */
-UNIV_INLINE
+/** Duplicate a string, allocated from a memory heap.
+@param[in] heap memory heap where string is allocated
+@param[in] str string to be copied
+@param[in] len length of str, in bytes
+@return own: a NUL-terminated copy of str */
+inline
char*
-mem_heap_strdupl(
-/*=============*/
- mem_heap_t* heap, /*!< in: memory heap where string is allocated */
- const char* str, /*!< in: string to be copied */
- ulint len); /*!< in: length of str, in bytes */
+mem_heap_strdupl(mem_heap_t* heap, const char* str, size_t len)
+{
+ char* s = static_cast<char*>(mem_heap_alloc(heap, len + 1));
+ s[len] = 0;
+ return(static_cast<char*>(memcpy(s, str, len)));
+}
/**********************************************************************//**
Concatenate two strings and return the result, using a memory heap.
@@ -325,16 +341,6 @@ mem_heap_strcat(
const char* s1, /*!< in: string 1 */
const char* s2); /*!< in: string 2 */
-/**********************************************************************//**
-Duplicate a block of data, allocated from a memory heap.
-@return own: a copy of the data */
-void*
-mem_heap_dup(
-/*=========*/
- mem_heap_t* heap, /*!< in: memory heap where copy is allocated */
- const void* data, /*!< in: data to be copied */
- ulint len); /*!< in: length of data, in bytes */
-
/****************************************************************//**
A simple sprintf replacement that dynamically allocates the space for the
formatted string from the given heap. This supports a very limited set of