-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(lib/runtime/wasmer): import functions in a for loop #2650
Conversation
Codecov Report
@@ Coverage Diff @@
## development #2650 +/- ##
===============================================
+ Coverage 62.34% 62.93% +0.58%
===============================================
Files 211 211
Lines 27343 27106 -237
===============================================
+ Hits 17048 17059 +11
+ Misses 8654 8486 -168
+ Partials 1641 1561 -80
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
func ImportsNodeRuntime() (imports *wasm.Imports, err error) { | ||
imports = wasm.NewImports() | ||
|
||
for _, toRegister := range []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be more clear to have this as a fixed-sized array outside of the function scope IMO
var importedFuncs = [...]struct{
import_name string
implementation interface{}
cgoPointer unsafe.Pointer
}{
...
}
for _, toRegister := importedFuncs {
_, err = imports.AppendFunction(toRegister.importName, toRegister.implementation, toRegister.cgoPointer)
if err != nil {
return nil, fmt.Errorf("importing function: %w", err)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely taking the fixed size array (god damn second time I don't use it, thanks for the reminder!).
Although I don't really see the point to have it at global scope 🤔 I don't think it would change performance wise, and it's only used in that function. It would also pollute more the (unexported) package Go API.
Keep in mind I'm a very pro-local-everything-activist
🎉 This PR is included in version 0.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
ImportsNodeRuntime
: append functions in a for loopImportsNodeRuntime
: remove no longer needed//nolint:gocyclo
ImportsNodeRuntime
: update now deprecated.Append
to be.AppendFunction
ImportsNodeRuntime
: sort import appending alphabeticallyTests
Issues
Done whilst adding functions
Primary Reviewer
@kishansagathiya