diff options
author | Volker Lendecke <vl@samba.org> | 2008-01-08 23:18:03 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-01-09 00:10:43 +0100 |
commit | 148f1eee4338bbe485f9b9bcf9569f76f906b665 (patch) | |
tree | 5aafb667c38c33ce8b6d7140a4ffaf3bdd9b3ec9 | |
parent | 0af2efcdc4cd669db2a2ee582674dc030c6371a9 (diff) | |
download | samba-148f1eee4338bbe485f9b9bcf9569f76f906b665.tar.gz samba-148f1eee4338bbe485f9b9bcf9569f76f906b665.tar.bz2 samba-148f1eee4338bbe485f9b9bcf9569f76f906b665.zip |
Save one popular malloc
(This used to be commit 2150663d9eaf5cdab08de2ad1fcc952d7e85936c)
-rw-r--r-- | source3/lib/ms_fnmatch.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c index a839b42588..8b69f1c2d2 100644 --- a/source3/lib/ms_fnmatch.c +++ b/source3/lib/ms_fnmatch.c @@ -152,6 +152,8 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, smb_ucs2_t *s = NULL; int ret, count, i; struct max_n *max_n = NULL; + struct max_n *max_n_free = NULL; + struct max_n one_max_n; if (ISDOTDOT(string)) { string = "."; @@ -201,17 +203,27 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, } if (count != 0) { - max_n = SMB_CALLOC_ARRAY(struct max_n, count); - if (!max_n) { - SAFE_FREE(p); - SAFE_FREE(s); - return -1; + if (count == 1) { + /* + * We're doing this a LOT, so save the effort to allocate + */ + ZERO_STRUCT(one_max_n); + max_n = &one_max_n; + } + else { + max_n = SMB_CALLOC_ARRAY(struct max_n, count); + if (!max_n) { + SAFE_FREE(p); + SAFE_FREE(s); + return -1; + } + max_n_free = max_n; } } ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive); - SAFE_FREE(max_n); + SAFE_FREE(max_n_free); SAFE_FREE(p); SAFE_FREE(s); return ret; |