Skip to content

Commit e8a0dbf

Browse files
committed
OPTIM: pattern: use malloc() to initialize new pat_ref struct
As mentioned in the previous commit, in _pat_ref_new(), it was not strictly needed to explicitly assign all struct members to 0 since the struct was allocated with calloc() which does the zeroing for us. However, it was verified that we already initialize all fields explictly, thus there is no reason to keep using calloc() instead of malloc(). In fact using malloc() is less expensive, so let's use that instead now.
1 parent d139740 commit e8a0dbf

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/pattern.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,13 +1801,11 @@ static struct pat_ref *_pat_ref_new(const char *display, unsigned int flags)
18011801
{
18021802
struct pat_ref *ref;
18031803

1804-
ref = calloc(1, sizeof(*ref));
1804+
ref = malloc(sizeof(*ref));
18051805
if (!ref)
18061806
return NULL;
18071807

1808-
/* For now is assumed <ref> was allocated with calloc() thus we don't
1809-
* have to explicitly set all members to 0.
1810-
*/
1808+
/* don't forget to explicitly initialize all pat_ref struct members */
18111809

18121810
if (display) {
18131811
ref->display = strdup(display);

0 commit comments

Comments
 (0)