Skip to content

Commit

Permalink
Inline definition of mem_heap_dup(), mem_heap_strdup(), mem_heap_strd…
Browse files Browse the repository at this point in the history
…upl()
  • Loading branch information
dr-m committed Sep 5, 2017
1 parent 83f9422 commit fe47aee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 66 deletions.
54 changes: 30 additions & 24 deletions storage/innobase/include/mem0mem.h
Expand Up @@ -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.
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions storage/innobase/include/mem0mem.ic
Expand Up @@ -586,20 +586,3 @@ mem_strdupl(
s[len] = 0;
return(static_cast<char*>(memcpy(s, str, len)));
}

/**********************************************************************//**
Makes a NUL-terminated copy of a nonterminated string,
allocated from a memory heap.
@return own: a copy of the string */
UNIV_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 */
{
char* s = (char*) mem_heap_alloc(heap, len + 1);
s[len] = 0;
return((char*) memcpy(s, str, len));
}
25 changes: 0 additions & 25 deletions storage/innobase/mem/mem0mem.cc
Expand Up @@ -31,31 +31,6 @@ Created 6/9/1994 Heikki Tuuri
#include "srv0srv.h"
#include <stdarg.h>

/** Duplicates 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 */
char*
mem_heap_strdup(
mem_heap_t* heap,
const char* str)
{
return(static_cast<char*>(mem_heap_dup(heap, str, strlen(str) + 1)));
}

/**********************************************************************//**
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 */
{
return(memcpy(mem_heap_alloc(heap, len), data, len));
}

/**********************************************************************//**
Concatenate two strings and return the result, using a memory heap.
@return own: the result */
Expand Down

0 comments on commit fe47aee

Please sign in to comment.