jq: Backport a bunch of commits in order to fix jq-1.6 terrible performance on startup
[feed/packages.git] / utils / jq / patches / 0006-Replace-TOP-before-imports-special-case-with-assert.patch
diff --git a/utils/jq/patches/0006-Replace-TOP-before-imports-special-case-with-assert.patch b/utils/jq/patches/0006-Replace-TOP-before-imports-special-case-with-assert.patch
new file mode 100644 (file)
index 0000000..ae2c406
--- /dev/null
@@ -0,0 +1,37 @@
+From a114b871e460ef2ddcf7698bc6b18651c976626a Mon Sep 17 00:00:00 2001
+From: Muh Muhten <muh.muhten@gmail.com>
+Date: Tue, 19 Feb 2019 00:14:53 -0500
+Subject: [PATCH 6/9] Replace TOP-before-imports special case with assert
+
+The case isn't actually possible afaict.
+---
+ src/compile.c | 11 ++++-------
+ 1 file changed, 4 insertions(+), 7 deletions(-)
+
+--- a/src/compile.c
++++ b/src/compile.c
+@@ -469,10 +469,10 @@ block block_drop_unreferenced(block body
+ jv block_take_imports(block* body) {
+   jv imports = jv_array();
+-  inst* top = NULL;
+-  if (body->first && body->first->op == TOP) {
+-    top = block_take(body);
+-  }
++  /* Parser should never generate TOP before imports */
++  assert(!(body->first && body->first->op == TOP && body->first->next &&
++        (body->first->next->op == MODULEMETA || body->first->next->op == DEPS)));
++
+   while (body->first && (body->first->op == MODULEMETA || body->first->op == DEPS)) {
+     inst* dep = block_take(body);
+     if (dep->op == DEPS) {
+@@ -480,9 +480,6 @@ jv block_take_imports(block* body) {
+     }
+     inst_free(dep);
+   }
+-  if (top) {
+-    *body = block_join(inst_block(top),*body);
+-  }
+   return imports;
+ }