-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: remove unnecessary json encode from wasm
- Loading branch information
Showing
17 changed files
with
189 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build js && wasm | ||
|
||
package entity | ||
|
||
import ( | ||
"syscall/js" | ||
) | ||
|
||
func (f *File) MarshalJavaScript() js.Value { | ||
return js.ValueOf(map[string]any{ | ||
"file_path": f.FilePath, | ||
"size": f.FullSize(), | ||
"pcln_size": f.PclnSize(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build !js && !wasm | ||
|
||
package entity | ||
|
||
import ( | ||
"github.com/go-json-experiment/json" | ||
"github.com/go-json-experiment/json/jsontext" | ||
) | ||
|
||
var FileMarshalerCompact = json.MarshalFuncV2[File](func(encoder *jsontext.Encoder, file File, options json.Options) error { | ||
err := encoder.WriteToken(jsontext.ObjectStart) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = json.MarshalEncode(encoder, "file_path", options); err != nil { | ||
return err | ||
} | ||
if err = json.MarshalEncode(encoder, file.FilePath, options); err != nil { | ||
return err | ||
} | ||
if err = json.MarshalEncode(encoder, "size", options); err != nil { | ||
return err | ||
} | ||
if err = json.MarshalEncode(encoder, file.FullSize(), options); err != nil { | ||
return err | ||
} | ||
if err = json.MarshalEncode(encoder, "pcln_size", options); err != nil { | ||
return err | ||
} | ||
if err = json.MarshalEncode(encoder, file.PclnSize(), options); err != nil { | ||
return err | ||
} | ||
|
||
err = encoder.WriteToken(jsontext.ObjectEnd) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build js && wasm | ||
|
||
package entity | ||
|
||
import ( | ||
"syscall/js" | ||
|
||
"github.com/samber/lo" | ||
) | ||
|
||
func (m PackageMap) MarshalJavaScript() js.Value { | ||
ret := map[string]any{} | ||
|
||
for k, v := range m { | ||
ret[k] = v.MarshalJavaScript() | ||
} | ||
|
||
return js.ValueOf(ret) | ||
} | ||
|
||
func (p *Package) MarshalJavaScript() js.Value { | ||
var symbols, files []any | ||
symbols = lo.Map(p.Symbols, func(s *Symbol, _ int) any { return s.MarshalJavaScript() }) | ||
files = lo.Map(p.Files, func(f *File, _ int) any { return f.MarshalJavaScript() }) | ||
|
||
return js.ValueOf(map[string]any{ | ||
"name": p.Name, | ||
"type": p.Type, | ||
"size": p.Size, | ||
"symbols": symbols, | ||
"subPackages": p.SubPackages.MarshalJavaScript(), | ||
"files": files, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build js && wasm | ||
|
||
package entity | ||
|
||
import ( | ||
"syscall/js" | ||
) | ||
|
||
func (s Section) MarshalJavaScript() js.Value { | ||
return js.ValueOf(map[string]any{ | ||
"name": s.Name, | ||
"size": s.Size, | ||
"file_size": s.FileSize, | ||
"known_size": s.KnownSize, | ||
"offset": s.Offset, | ||
"end": s.End, | ||
"addr": s.Addr, | ||
"addr_end": s.AddrEnd, | ||
"only_in_memory": s.OnlyInMemory, | ||
"debug": s.Debug, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//go:build js && wasm | ||
|
||
package entity | ||
|
||
import ( | ||
"syscall/js" | ||
) | ||
|
||
func (s *Symbol) MarshalJavaScript() js.Value { | ||
return js.ValueOf(map[string]any{ | ||
"name": s.Name, | ||
"addr": s.Addr, | ||
"size": s.Size, | ||
"type": s.Type, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build js && wasm | ||
|
||
package wasm | ||
|
||
import ( | ||
"syscall/js" | ||
|
||
"github.com/Zxilly/go-size-analyzer/internal/result" | ||
) | ||
|
||
func JavaScript(r *result.Result) js.Value { | ||
return r.MarshalJavaScript() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build js && wasm | ||
|
||
package result | ||
|
||
import ( | ||
"syscall/js" | ||
|
||
"github.com/samber/lo" | ||
|
||
"github.com/Zxilly/go-size-analyzer/internal/entity" | ||
) | ||
|
||
func (r *Result) MarshalJavaScript() js.Value { | ||
var sections []any | ||
sections = lo.Map(r.Sections, func(s *entity.Section, _ int) any { | ||
return s.MarshalJavaScript() | ||
}) | ||
|
||
return js.ValueOf(map[string]any{ | ||
"name": r.Name, | ||
"size": r.Size, | ||
"packages": r.Packages.MarshalJavaScript(), | ||
"sections": sections, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.