mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 23:08:32 +00:00
ast_frdup optimization: only call strlen once and save the result
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2801 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
10
frame.c
10
frame.c
@@ -282,13 +282,15 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
|||||||
struct ast_frame *ast_frdup(struct ast_frame *f)
|
struct ast_frame *ast_frdup(struct ast_frame *f)
|
||||||
{
|
{
|
||||||
struct ast_frame *out;
|
struct ast_frame *out;
|
||||||
int len;
|
int len, srclen = 0;
|
||||||
void *buf;
|
void *buf;
|
||||||
/* Start with standard stuff */
|
/* Start with standard stuff */
|
||||||
len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
|
len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
|
||||||
/* If we have a source, add space for it */
|
/* If we have a source, add space for it */
|
||||||
if (f->src && strlen(f->src))
|
if (f->src)
|
||||||
len += strlen(f->src) + 1;
|
srclen = strlen(f->src);
|
||||||
|
if (srclen > 0)
|
||||||
|
len += srclen + 1;
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -303,7 +305,7 @@ struct ast_frame *ast_frdup(struct ast_frame *f)
|
|||||||
out->mallocd = AST_MALLOCD_HDR;
|
out->mallocd = AST_MALLOCD_HDR;
|
||||||
out->offset = AST_FRIENDLY_OFFSET;
|
out->offset = AST_FRIENDLY_OFFSET;
|
||||||
out->data = buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
|
out->data = buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
|
||||||
if (f->src && strlen(f->src)) {
|
if (srclen > 0) {
|
||||||
out->src = out->data + f->datalen;
|
out->src = out->data + f->datalen;
|
||||||
/* Must have space since we allocated for it */
|
/* Must have space since we allocated for it */
|
||||||
strcpy(out->src, f->src);
|
strcpy(out->src, f->src);
|
||||||
|
|||||||
Reference in New Issue
Block a user