Pull everything except the actual run call out of the closure
authortb <tb@openbsd.org>
Mon, 6 Nov 2023 15:21:44 +0000 (15:21 +0000)
committertb <tb@openbsd.org>
Mon, 6 Nov 2023 15:21:44 +0000 (15:21 +0000)
The determination of the test group type and the JSON unmarshalling can be
done before the closure without performance impact. This is more readable
and eliminates the need of a temporary variable again.

Suggested by jsing

regress/lib/libcrypto/wycheproof/wycheproof.go

index feeb6c8..39f1456 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: wycheproof.go,v 1.150 2023/11/06 15:17:02 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.151 2023/11/06 15:21:44 tb Exp $ */
 /*
  * Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
  * Copyright (c) 2018,2019,2022 Theo Buehler <tb@openbsd.org>
@@ -2830,17 +2830,15 @@ func runTestVectors(path string, variant testVariant) bool {
 
        success := true
        for _, tg := range wtv.TestGroups {
-               testGroupJSON := tg
+               wtg := testGroupFromAlgorithm(wtv.Algorithm, variant)
+               if wtg == nil {
+                       log.Printf("INFO: Unknown test vector algorithm %q", wtv.Algorithm)
+                       return false
+               }
+               if err := json.Unmarshal(tg, wtg); err != nil {
+                       log.Fatalf("Failed to unmarshal test groups JSON: %v", err)
+               }
                testc.runTest(func() bool {
-                       wtg := testGroupFromAlgorithm(wtv.Algorithm, variant)
-                       if wtg == nil {
-                               log.Printf("INFO: Unknown test vector algorithm %q", wtv.Algorithm)
-                               return false
-                       }
-
-                       if err := json.Unmarshal(testGroupJSON, wtg); err != nil {
-                               log.Fatalf("Failed to unmarshal test groups JSON: %v", err)
-                       }
                        return wtg.run(wtv.Algorithm, variant)
                })
        }