aboutsummaryrefslogtreecommitdiffstats
path: root/frame.c
diff options
context:
space:
mode:
authorcitats <citats@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-28 17:54:01 +0000
committercitats <citats@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-28 17:54:01 +0000
commit99902cd21f336edaf335ed2264d796679476e3a2 (patch)
tree892d4e3bddbd1749b45b113c7a9797cad3917f2c /frame.c
parent27021f3e234b58eb9b045e4633d0735c2e273df9 (diff)
ast_frdup optimization: only call strlen once and save the result
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2801 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'frame.c')
-rwxr-xr-xframe.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/frame.c b/frame.c
index 3fa8ff5d6..b8709eee1 100755
--- a/frame.c
+++ b/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 *out;
- int len;
+ int len, srclen = 0;
void *buf;
/* Start with standard stuff */
len = sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET + f->datalen;
/* If we have a source, add space for it */
- if (f->src && strlen(f->src))
- len += strlen(f->src) + 1;
+ if (f->src)
+ srclen = strlen(f->src);
+ if (srclen > 0)
+ len += srclen + 1;
buf = malloc(len);
if (!buf)
return NULL;
@@ -303,7 +305,7 @@ struct ast_frame *ast_frdup(struct ast_frame *f)
out->mallocd = AST_MALLOCD_HDR;
out->offset = 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;
/* Must have space since we allocated for it */
strcpy(out->src, f->src);