aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2020-01-26 20:20:58 +0200
committerArnold D. Robbins <arnold@skeeve.com>2020-01-26 20:20:58 +0200
commit455542e5a75843bb16c9e747fb63a8731021bf85 (patch)
treedb68ad5822c27606796db7ca5f30af8082c6e63f
parent11e6edec3f68a8b4e3e218001e5c6a943aa30f63 (diff)
downloadegawk-455542e5a75843bb16c9e747fb63a8731021bf85.tar.gz
egawk-455542e5a75843bb16c9e747fb63a8731021bf85.tar.bz2
egawk-455542e5a75843bb16c9e747fb63a8731021bf85.zip
Efficiency improvement.
-rw-r--r--ChangeLog5
-rw-r--r--array.c21
2 files changed, 16 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 1ed8cd50..0a0e2031 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-26 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * array.c (sort_up_value_type): Small efficiency tweak. Only
+ run through the list of other types if both values are not scalars.
+
2020-01-24 Arnold D. Robbins <arnold@skeeve.com>
* array.c, profile.c, cint_array.c, builtin.c, interpret.h,
diff --git a/array.c b/array.c
index ae21b32a..fa9c2d95 100644
--- a/array.c
+++ b/array.c
@@ -1153,7 +1153,6 @@ static int
sort_up_value_type(const void *p1, const void *p2)
{
NODE *n1, *n2;
- int n1_pos, n2_pos, i;
static const NODETYPE element_types[] = {
Node_builtin_func,
@@ -1180,19 +1179,21 @@ sort_up_value_type(const void *p1, const void *p2)
}
/* 2. Non scalars */
- n1_pos = n2_pos = -1;
- for (i = 0; element_types[i] != Node_illegal; i++) {
- if (n1->type == element_types[i])
- n1_pos = i;
+ if (n1->type != Node_val || n2->type != Node_val) {
+ int n1_pos, n2_pos, i;
- if (n2->type == element_types[i])
- n2_pos = i;
- }
+ n1_pos = n2_pos = -1;
+ for (i = 0; element_types[i] != Node_illegal; i++) {
+ if (n1->type == element_types[i])
+ n1_pos = i;
- assert(n1_pos != -1 && n2_pos != -1);
+ if (n2->type == element_types[i])
+ n2_pos = i;
+ }
- if (n1->type != Node_val || n2->type != Node_val)
+ assert(n1_pos != -1 && n2_pos != -1);
return (n1_pos - n2_pos);
+ }
/* two scalars */
(void) fixtype(n1);