Commit fe47aee3 authored by Marko Mäkelä's avatar Marko Mäkelä

Inline definition of mem_heap_dup(), mem_heap_strdup(), mem_heap_strdupl()

parent 83f9422f
......@@ -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
......
......@@ -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));
}
......@@ -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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment