Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions erts/emulator/beam/erl_db_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ Eterm db_prog_match(Process *c_p,
Process *tmpp;
Process *current_scheduled;
ErtsSchedulerData *esdp;
Eterm (*bif)(Process*, ...);
BIF_RETTYPE (*bif)(BIF_ALIST);
Eterm bif_args[3];
int fail_label;
#ifdef DMC_DEBUG
Expand Down Expand Up @@ -2338,8 +2338,8 @@ Eterm db_prog_match(Process *c_p,
*esp++ = t;
break;
case matchCall0:
bif = (Eterm (*)(Process*, ...)) *pc++;
t = (*bif)(build_proc, bif_args);
bif = (BIF_RETTYPE (*)(BIF_ALIST)) *pc++;
t = (*bif)(build_proc, bif_args, NULL);
if (is_non_value(t)) {
if (do_catch)
t = FAIL_TERM;
Expand All @@ -2349,8 +2349,8 @@ Eterm db_prog_match(Process *c_p,
*esp++ = t;
break;
case matchCall1:
bif = (Eterm (*)(Process*, ...)) *pc++;
t = (*bif)(build_proc, esp-1);
bif = (BIF_RETTYPE (*)(BIF_ALIST)) *pc++;
t = (*bif)(build_proc, esp-1, NULL);
Copy link
Contributor Author

@tehprofessor tehprofessor Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got everything updated correctly. The one thing I'm not entirely sure of is if this should be copied into bif_args, if this is an optimization for this specific case, or something else? I'm new to c; so, if I'm understanding this correctly, esp-1 works here without copying into bif_args because esp-1 and bif_args[0] essentially point to the same value and both are pointers so semantically it's all good? Then by not copying into bif_args[0] we save an allocation/step?

And, please feel free to tell me to just google more 😄 !

Thank you both for your time reviewing this, and please let me know if there's anything else I can change, improve, or have missed 😅 here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copying of the arguments to bif_args when there are 2 or 3 arguments is only necessary because the arguments would be in the wrong order if we would pass esp-2 or esp-3, respectively. When there is a single argument, there is no need to copy it because it can't be in the wrong order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @bjorng

if (is_non_value(t)) {
if (do_catch)
t = FAIL_TERM;
Expand All @@ -2360,10 +2360,10 @@ Eterm db_prog_match(Process *c_p,
esp[-1] = t;
break;
case matchCall2:
bif = (Eterm (*)(Process*, ...)) *pc++;
bif = (BIF_RETTYPE (*)(BIF_ALIST)) *pc++;
bif_args[0] = esp[-1];
bif_args[1] = esp[-2];
t = (*bif)(build_proc, bif_args);
t = (*bif)(build_proc, bif_args, NULL);
if (is_non_value(t)) {
if (do_catch)
t = FAIL_TERM;
Expand All @@ -2374,11 +2374,11 @@ Eterm db_prog_match(Process *c_p,
esp[-1] = t;
break;
case matchCall3:
bif = (Eterm (*)(Process*, ...)) *pc++;
bif = (BIF_RETTYPE (*)(BIF_ALIST)) *pc++;
bif_args[0] = esp[-1];
bif_args[1] = esp[-2];
bif_args[2] = esp[-3];
t = (*bif)(build_proc, bif_args);
t = (*bif)(build_proc, bif_args, NULL);
if (is_non_value(t)) {
if (do_catch)
t = FAIL_TERM;
Expand Down