From 7153f9809d640cf4649fda9d2d51bd406e43e617 Mon Sep 17 00:00:00 2001 From: Per Hedbor <ph@opera.com> Date: Mon, 20 May 2013 21:03:20 +0200 Subject: [PATCH] The operation "empty_string += string" is now significantly faster. This is rather common in code that works with buffers. Previously it was, somewhat surpisingly, significantly faster to write code like: if( strlen( x ) ) x += str; else x = str; than it was to simply add the str to x regardless of whether or not x already had contents. Now the check is done in `+() instead. However, it still does not handle things like "" + str + "", which might perhaps be useful, but is significantly less common in real code. str + "" was already handled. --- src/operators.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/operators.c b/src/operators.c index 9e40ffb91f..5f0c741df1 100644 --- a/src/operators.c +++ b/src/operators.c @@ -1571,7 +1571,13 @@ PMOD_EXPORT void f_add(INT32 args) pop_n_elems(args-1); return; } - + else if(args == 2 && (size == sp[-1].u.string->len)) + { + stack_swap(); + pop_stack(); + return; + } + tmp=sp[-args].u.string->len; r=new_realloc_shared_string(sp[-args].u.string,size,max_shift); mark_free_svalue (sp - args); -- GitLab