diff --git a/.github/workflows/.ignore_words b/.github/workflows/.ignore_words new file mode 100644 index 000000000..ee952acef --- /dev/null +++ b/.github/workflows/.ignore_words @@ -0,0 +1,6 @@ +socio-economic +nd +regArgs +oders +ure +alse diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..5200258ac --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,13 @@ +name: Lint + +on: pull_request + +jobs: + misc: + runs-on: [self-hosted, X64] + steps: + - uses: actions/checkout@v4 + - name: spell check + run: | + pip install codespell==2.3.0 + git grep --cached -l '' | xargs codespell --skip 'fuzz/*,*_test.tmpl,testdata/*,*_test.go,go.mod,go.sum,*.gz' --ignore-words=.github/workflows/.ignore_words diff --git a/README.md b/README.md index 5f609b1c3..9d3d69164 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ ret, err := Encode(v, EscapeHTML) // ret == `{"\u0026\u0026":{"X":"\u003c\u003e" ### Compact Format -Sonic encodes primitive objects (struct/map...) as compact-format JSON by default, except marshaling `json.RawMessage` or `json.Marshaler`: sonic ensures validating their output JSON but **DONOT** compacting them for performance concerns. We provide the option `encoder.CompactMarshaler` to add compacting process. +Sonic encodes primitive objects (struct/map...) as compact-format JSON by default, except marshaling `json.RawMessage` or `json.Marshaler`: sonic ensures validating their output JSON but **DO NOT** compacting them for performance concerns. We provide the option `encoder.CompactMarshaler` to add compacting process. ### Print Error @@ -480,7 +480,7 @@ But `ast.Visitor` is not a very handy API. You might need to write a lot of code ### Buffer Size -Sonic use memory pool in many places like `encoder.Encode`, `ast.Node.MarshalJSON` to improve performace, which may produce more memory usage (in-use) when server's load is high. See [issue 614](https://github.com/bytedance/sonic/issues/614). Therefore, we introduce some options to let user control the behavior of memory pool. See [option](https://pkg.go.dev/github.com/bytedance/sonic@v1.11.9/option#pkg-variables) package. +Sonic use memory pool in many places like `encoder.Encode`, `ast.Node.MarshalJSON` to improve performance, which may produce more memory usage (in-use) when server's load is high. See [issue 614](https://github.com/bytedance/sonic/issues/614). Therefore, we introduce some options to let user control the behavior of memory pool. See [option](https://pkg.go.dev/github.com/bytedance/sonic@v1.11.9/option#pkg-variables) package. ### Faster JSON skip diff --git a/api.go b/api.go index 9ac7bd6b5..406715eca 100644 --- a/api.go +++ b/api.go @@ -120,7 +120,7 @@ var ( // API is a binding of specific config. // This interface is inspired by github.com/json-iterator/go, -// and has same behaviors under equavilent config. +// and has same behaviors under equivalent config. type API interface { // MarshalToString returns the JSON encoding string of v MarshalToString(v interface{}) (string, error) diff --git a/ast/api_compat.go b/ast/api_compat.go index a349afc0b..6541e219d 100644 --- a/ast/api_compat.go +++ b/ast/api_compat.go @@ -34,7 +34,7 @@ func quote(buf *[]byte, val string) { quoteString(buf, val) } -// unquote unescapes a internal JSON string (it doesn't count quotas at the begining and end) +// unquote unescapes an internal JSON string (it doesn't count quotas at the beginning and end) func unquote(src string) (string, types.ParsingError) { sp := rt.IndexChar(src, -1) out, ok := unquoteBytes(rt.BytesFrom(sp, len(src)+2, len(src)+2)) diff --git a/ast/decode.go b/ast/decode.go index 27aaf1408..135ee6eb8 100644 --- a/ast/decode.go +++ b/ast/decode.go @@ -27,7 +27,7 @@ import ( "github.com/bytedance/sonic/internal/utils" ) -// Hack: this is used for both checking space and cause firendly compile errors in 32-bit arch. +// Hack: this is used for both checking space and cause friendly compile errors in 32-bit arch. const _Sonic_Not_Support_32Bit_Arch__Checking_32Bit_Arch_Here = (1 << ' ') | (1 << '\t') | (1 << '\r') | (1 << '\n') var bytesNull = []byte("null") diff --git a/ast/iterator.go b/ast/iterator.go index 076647154..1052dd0a0 100644 --- a/ast/iterator.go +++ b/ast/iterator.go @@ -173,7 +173,7 @@ type Scanner func(path Sequence, node *Node) bool // ForEach scans one V_OBJECT node's children from JSON head to tail, // and pass the Sequence and Node of corresponding JSON value. // -// Especailly, if the node is not V_ARRAY or V_OBJECT, +// Especially, if the node is not V_ARRAY or V_OBJECT, // the node itself will be returned and Sequence.Index == -1. // // NOTICE: A unsetted node WON'T trigger sc, but its index still counts into Path.Index diff --git a/ast/node.go b/ast/node.go index 0fbcf7835..2bb504850 100644 --- a/ast/node.go +++ b/ast/node.go @@ -140,7 +140,7 @@ func (self *Node) Check() error { // isRaw returns true if node's underlying value is raw json // -// Deprecated: not concurent safe +// Deprecated: not concurrent safe func (self Node) IsRaw() bool { return self.t & _V_RAW != 0 } @@ -440,7 +440,7 @@ func (self *Node) String() (string, error) { } } -// StrictString returns string value (unescaped), includeing V_STRING, V_ANY of string. +// StrictString returns string value (unescaped), including V_STRING, V_ANY of string. // In other cases, it will return empty string. func (self *Node) StrictString() (string, error) { if err := self.checkRaw(); err != nil { @@ -509,7 +509,7 @@ func (self *Node) Float64() (float64, error) { } } -// Float64 exports underlying float64 value, includeing V_NUMBER, V_ANY +// Float64 exports underlying float64 value, including V_NUMBER, V_ANY func (self *Node) StrictFloat64() (float64, error) { if err := self.checkRaw(); err != nil { return 0.0, err @@ -527,7 +527,7 @@ func (self *Node) StrictFloat64() (float64, error) { } } -/** Sequencial Value Methods **/ +/** Sequential Value Methods **/ // Len returns children count of a array|object|string node // WARN: For partially loaded node, it also works but only counts the parsed children @@ -611,7 +611,7 @@ func (self *Node) Unset(key string) (bool, error) { if err := self.should(types.V_OBJECT); err != nil { return false, err } - // NOTICE: must get acurate length before deduct + // NOTICE: must get accurate length before deduct if err := self.skipAllKey(); err != nil { return false, err } @@ -657,7 +657,7 @@ func (self *Node) SetAnyByIndex(index int, val interface{}) (bool, error) { return self.SetByIndex(index, NewAny(val)) } -// UnsetByIndex REOMVE (softly) the node of given index. +// UnsetByIndex REMOVE (softly) the node of given index. // // WARN: this will change address of elements, which is a dangerous action. // Use Unset() for object or Pop() for array instead. @@ -957,7 +957,7 @@ func (self *Node) MapUseNumber() (map[string]interface{}, error) { return self.toGenericObjectUseNumber() } -// MapUseNode scans both parsed and non-parsed chidren nodes, +// MapUseNode scans both parsed and non-parsed children nodes, // and map them by their keys func (self *Node) MapUseNode() (map[string]Node, error) { if self.isAny() { @@ -1102,7 +1102,7 @@ func (self *Node) ArrayUseNumber() ([]interface{}, error) { return self.toGenericArrayUseNumber() } -// ArrayUseNode copys both parsed and non-parsed chidren nodes, +// ArrayUseNode copies both parsed and non-parsed children nodes, // and indexes them by original order func (self *Node) ArrayUseNode() ([]Node, error) { if self.isAny() { @@ -1147,9 +1147,9 @@ func (self *Node) unsafeArray() (*linkedNodes, error) { return (*linkedNodes)(self.p), nil } -// Interface loads all children under all pathes from this node, +// Interface loads all children under all paths from this node, // and converts itself as generic type. -// WARN: all numberic nodes are casted to float64 +// WARN: all numeric nodes are casted to float64 func (self *Node) Interface() (interface{}, error) { if err := self.checkRaw(); err != nil { return nil, err @@ -1193,7 +1193,7 @@ func (self *Node) packAny() interface{} { } // InterfaceUseNumber works same with Interface() -// except numberic nodes are casted to json.Number +// except numeric nodes are casted to json.Number func (self *Node) InterfaceUseNumber() (interface{}, error) { if err := self.checkRaw(); err != nil { return nil, err diff --git a/decoder/decoder_compat.go b/decoder/decoder_compat.go index 81e1ae4e3..a0e1de4da 100644 --- a/decoder/decoder_compat.go +++ b/decoder/decoder_compat.go @@ -192,5 +192,5 @@ func (s SyntaxError) Error() string { return (*json.SyntaxError)(unsafe.Pointer(&s)).Error() } -// MismatchTypeError represents dismatching between json and object -type MismatchTypeError json.UnmarshalTypeError \ No newline at end of file +// MismatchTypeError represents mismatching between json and object +type MismatchTypeError json.UnmarshalTypeError diff --git a/decoder/decoder_native.go b/decoder/decoder_native.go index 9317d57f6..450dfb624 100644 --- a/decoder/decoder_native.go +++ b/decoder/decoder_native.go @@ -30,7 +30,7 @@ type Decoder = api.Decoder // SyntaxError represents json syntax error type SyntaxError = api.SyntaxError -// MismatchTypeError represents dismatching between json and object +// MismatchTypeError represents mismatching between json and object type MismatchTypeError = api.MismatchTypeError // Options for decode. diff --git a/docs/INTRODUCTION.md b/docs/INTRODUCTION.md index 2ec8e4880..4266c46e6 100644 --- a/docs/INTRODUCTION.md +++ b/docs/INTRODUCTION.md @@ -14,7 +14,7 @@ Therefore, we decided to **develop a brand-new JSON library with high performanc Before starting our design, we need to figure out some questions: ### Why is Json-iterator faster than Standard Library? -First of all, the **schema-based processing mechanism** used by the standard library is commendable, in which the parser can obtain meta information in advance when scanning, thereby shortening the time of branch selection. However, its original implementation did not make good use of this mechanism, instead, **it spent a lot of time reflecting to obtain meta info of schema**. Meanwhile, The approach of json-iterator is: Interprete structure as field-by-field encoding and decoding functions, and then assembled and cached them, minimizing the performance loss cost by reflection. But does it work once and for all? No. In practical tests, we found that **the deeper and larger the input JSON got, the smaller the gap between json-iterator and other libraries gradually became** - eventually event got surpassed: +First of all, the **schema-based processing mechanism** used by the standard library is commendable, in which the parser can obtain meta information in advance when scanning, thereby shortening the time of branch selection. However, its original implementation did not make good use of this mechanism, instead, **it spent a lot of time reflecting to obtain meta info of schema**. Meanwhile, The approach of json-iterator is: Interpret structure as field-by-field encoding and decoding functions, and then assembled and cached them, minimizing the performance loss cost by reflection. But does it work once and for all? No. In practical tests, we found that **the deeper and larger the input JSON got, the smaller the gap between json-iterator and other libraries gradually became** - eventually event got surpassed: ![Scalability](./imgs/introduction-1.png) The reason is that **this implementation transforms into a large number of interface encapsulations and function calls**, followed by function-call losses: diff --git a/internal/decoder/api/decoder_arm64.go b/internal/decoder/api/decoder_arm64.go index 65a9478b4..16e55965a 100644 --- a/internal/decoder/api/decoder_arm64.go +++ b/internal/decoder/api/decoder_arm64.go @@ -30,7 +30,7 @@ var ( func init() { - // whe in aarch64. we enable all optimize + // when in aarch64, we enable all optimization envs.EnableOptDec() envs.EnableFastMap() } diff --git a/internal/decoder/jitdec/assembler_regabi_amd64.go b/internal/decoder/jitdec/assembler_regabi_amd64.go index 76eef333b..42b8b502f 100644 --- a/internal/decoder/jitdec/assembler_regabi_amd64.go +++ b/internal/decoder/jitdec/assembler_regabi_amd64.go @@ -67,7 +67,7 @@ import ( */ const ( - _FP_args = 72 // 72 bytes to pass and spill register arguements + _FP_args = 72 // 72 bytes to pass and spill register arguments _FP_fargs = 80 // 80 bytes for passing arguments to other Go functions _FP_saves = 48 // 48 bytes for saving the registers before CALL instructions _FP_locals = 144 // 144 bytes for local variables @@ -203,9 +203,9 @@ var ( var _VAR_fl = jit.Ptr(_SP, _FP_fargs + _FP_saves + 112) var ( - _VAR_et = jit.Ptr(_SP, _FP_fargs + _FP_saves + 120) // save dismatched type + _VAR_et = jit.Ptr(_SP, _FP_fargs + _FP_saves + 120) // save mismatched type _VAR_pc = jit.Ptr(_SP, _FP_fargs + _FP_saves + 128) // save skip return pc - _VAR_ic = jit.Ptr(_SP, _FP_fargs + _FP_saves + 136) // save dismatched position + _VAR_ic = jit.Ptr(_SP, _FP_fargs + _FP_saves + 136) // save mismatched position ) type _Assembler struct { @@ -1361,7 +1361,7 @@ func (self *_Assembler) _asm_OP_num(_ *_Instr) { self.Emit("MOVQ", _R9, _VAR_pc) self.Sjmp("JMP" , _LB_skip_one) - /* assgin string */ + /* assign string */ self.Link("_num_next_{n}") self.slice_from_r(_AX, 0) self.Emit("BTQ", jit.Imm(_F_copy_string), _ARG_fv) diff --git a/internal/decoder/jitdec/compiler.go b/internal/decoder/jitdec/compiler.go index a097d171d..33191262a 100644 --- a/internal/decoder/jitdec/compiler.go +++ b/internal/decoder/jitdec/compiler.go @@ -736,7 +736,7 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) { self.tab[et] = true /* not inline the pointer type - * recursing the defined pointer type's elem will casue issue379. + * recursing the defined pointer type's elem will cause issue379. */ self.compileOps(p, sp, et) } diff --git a/internal/decoder/jitdec/pools.go b/internal/decoder/jitdec/pools.go index 01868cb2f..200af6a60 100644 --- a/internal/decoder/jitdec/pools.go +++ b/internal/decoder/jitdec/pools.go @@ -63,8 +63,8 @@ type _Decoder func( vp unsafe.Pointer, sb *_Stack, fv uint64, - sv string, // DO NOT pass value to this arguement, since it is only used for local _VAR_sv - vk unsafe.Pointer, // DO NOT pass value to this arguement, since it is only used for local _VAR_vk + sv string, // DO NOT pass value to this argument, since it is only used for local _VAR_sv + vk unsafe.Pointer, // DO NOT pass value to this argument, since it is only used for local _VAR_vk ) (int, error) var _KeepAlive struct { diff --git a/internal/decoder/optdec/compiler.go b/internal/decoder/optdec/compiler.go index fd164af93..7d9d60a01 100644 --- a/internal/decoder/optdec/compiler.go +++ b/internal/decoder/optdec/compiler.go @@ -177,7 +177,7 @@ func (c *compiler) compilePtr(vt reflect.Type) decFunc { c.enter(vt) defer c.exit(vt) - // specail logic for Named Ptr, issue 379 + // special logic for Named Ptr, issue 379 if reflect.PtrTo(vt.Elem()) != vt { c.namedPtr = true return &ptrDecoder{ @@ -432,7 +432,7 @@ func (c *compiler) tryCompilePtrUnmarshaler(vt reflect.Type, strOpt bool) decFun /* check for `encoding.TextMarshaler` with pointer receiver */ if pt.Implements(encodingTextUnmarshalerType) { - /* TextUnmarshal not support ,strig tag */ + /* TextUnmarshal not support, string tag */ if strOpt { panicForInvalidStrType(vt) } diff --git a/internal/decoder/optdec/helper.go b/internal/decoder/optdec/helper.go index 7bf8a8f39..61faa6c80 100644 --- a/internal/decoder/optdec/helper.go +++ b/internal/decoder/optdec/helper.go @@ -11,7 +11,7 @@ import ( func SkipNumberFast(json string, start int) (int, bool) { - // find the number ending, we pasred in native, it alway valid + // find the number ending, we parsed in native, it always valid pos := start for pos < len(json) && json[pos] != ']' && json[pos] != '}' && json[pos] != ',' { if json[pos] >= '0' && json[pos] <= '9' || json[pos] == '.' || json[pos] == '-' || json[pos] == '+' || json[pos] == 'e' || json[pos] == 'E' { @@ -40,7 +40,7 @@ func ValidNumberFast(raw string) bool { return false } - // check trainling chars + // check trailing chars for ret < len(raw) { return false } @@ -49,7 +49,7 @@ func ValidNumberFast(raw string) bool { } func SkipOneFast2(json string, pos *int) (int, error) { - // find the number ending, we pasred in sonic-cpp, it alway valid + // find the number ending, we parsed in sonic-cpp, it always valid start := native.SkipOneFast(&json, pos) if start < 0 { return -1, error_syntax(*pos, json, types.ParsingError(-start).Error()) @@ -58,7 +58,7 @@ func SkipOneFast2(json string, pos *int) (int, error) { } func SkipOneFast(json string, pos int) (string, error) { - // find the number ending, we pasred in sonic-cpp, it alway valid + // find the number ending, we parsed in sonic-cpp, it always valid start := native.SkipOneFast(&json, &pos) if start < 0 { // TODO: details error code diff --git a/internal/decoder/optdec/native.go b/internal/decoder/optdec/native.go index 29a0136ae..5dadec0b7 100644 --- a/internal/decoder/optdec/native.go +++ b/internal/decoder/optdec/native.go @@ -61,13 +61,13 @@ type node struct { val uint64 } -// should consitent with native/parser.c +// should consistent with native/parser.c type _nospaceBlock struct { _ [8]byte _ [8]byte } -// should consitent with native/parser.c +// should consistent with native/parser.c type nodeBuf struct { ncur uintptr parent int64 @@ -84,7 +84,7 @@ func (self *nodeBuf) init(nodes []node) { self.parent = -1 } -// should consitent with native/parser.c +// should consistent with native/parser.c type Parser struct { Json string padded []byte diff --git a/internal/decoder/optdec/node.go b/internal/decoder/optdec/node.go index 3f60a3368..b23901e38 100644 --- a/internal/decoder/optdec/node.go +++ b/internal/decoder/optdec/node.go @@ -372,7 +372,7 @@ func (val Node) ParseF64(ctx *Context) (float64, bool) { } func (val Node) ParseString(ctx *Context) (string, bool) { - // shoud not use AsStrRef + // should not use AsStrRef s, ok := val.AsStr(ctx) if !ok { return "", false @@ -391,7 +391,7 @@ func (val Node) ParseString(ctx *Context) (string, bool) { func (val Node) ParseNumber(ctx *Context) (json.Number, bool) { - // shoud not use AsStrRef + // should not use AsStrRef s, ok := val.AsStr(ctx) if !ok { return json.Number(""), false diff --git a/internal/encoder/alg/sort.go b/internal/encoder/alg/sort.go index 9b69bce9a..5bb0f9011 100644 --- a/internal/encoder/alg/sort.go +++ b/internal/encoder/alg/sort.go @@ -46,7 +46,7 @@ func radixQsort(kvs []_MapPair, d, maxDepth int) { } // kvs[0:lt] < v = kvs[lt:gt] < kvs[gt:len(kvs)] - // Native implemention: + // Native implementation: // radixQsort(kvs[:lt], d, maxDepth) // if p > -1 { // radixQsort(kvs[lt:gt], d+1, maxDepth) diff --git a/internal/encoder/x86/assembler_regabi_amd64.go b/internal/encoder/x86/assembler_regabi_amd64.go index 95f452a02..c0912fb81 100644 --- a/internal/encoder/x86/assembler_regabi_amd64.go +++ b/internal/encoder/x86/assembler_regabi_amd64.go @@ -673,7 +673,7 @@ func (self *Assembler) encode_string(doubleQuote bool) { self.Sjmp("JMP", _LB_panic) self.Link("_str_next_{n}") - /* openning quote, check for double quote */ + /* opening quote, check for double quote */ if !doubleQuote { self.check_size_r(_AX, 2) // SIZE $2 self.add_char('"') // CHAR $'"' diff --git a/internal/optcaching/fcache.go b/internal/optcaching/fcache.go index afa7e7105..40b3e081f 100644 --- a/internal/optcaching/fcache.go +++ b/internal/optcaching/fcache.go @@ -84,7 +84,7 @@ func NewSmallFieldMap (hint int) *SmallFieldMap { func (self *SmallFieldMap) Set(fields []resolver.FieldMeta) { if len(fields) > 8 { - panic("small field map shoud use in small struct") + panic("small field map should use in small struct") } for i, f := range fields { @@ -254,7 +254,7 @@ type keysInfo struct { func (self *NormalFieldMap) Set(fields []resolver.FieldMeta) { if len(fields) <=8 || len(fields) > 128 { - panic("normal field map shoud use in small struct") + panic("normal field map should use in small struct") } // allocate the flat map in []byte @@ -278,7 +278,7 @@ func (self *NormalFieldMap) Set(fields []resolver.FieldMeta) { } - // add a padding size at last to make it firendly for SIMD. + // add a padding size at last to make it friendly for SIMD. self.keys = make([]byte, _HdrSize + 2 * kvLen, _HdrSize + 2 * kvLen + _PaddingSize) self.lowOffset = _HdrSize + kvLen diff --git a/internal/rt/stubs.go b/internal/rt/stubs.go index 5104a0793..1074f491b 100644 --- a/internal/rt/stubs.go +++ b/internal/rt/stubs.go @@ -153,7 +153,7 @@ func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice { new := GrowSlice(et, *old, newLen) - // we sould clear the memory from [oldLen:newLen] + // we should clear the memory from [oldLen:newLen] if et.PtrData == 0 { oldlenmem := uintptr(old.Len) * et.Size newlenmem := uintptr(newLen) * et.Size diff --git a/loader/funcdata_compat.go b/loader/funcdata_compat.go index 17c840613..b4a24bcd6 100644 --- a/loader/funcdata_compat.go +++ b/loader/funcdata_compat.go @@ -329,7 +329,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte funcnametab, nameOffs := makeFuncnameTab(funcs) mod.funcnametab = funcnametab - // mmap() text and funcdata segements + // mmap() text and funcdata segments p := os.Getpagesize() size := int(rnd(int64(len(text)), int64(p))) addr := mmap(size) @@ -389,7 +389,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte pclnOffset: getOffsetOf(moduledata{}, "pclntable"), } - // sepecial case: gcdata and gcbss must by non-empty + // special case: gcdata and gcbss must by non-empty mod.gcdata = uintptr(unsafe.Pointer(&emptyByte)) mod.gcbss = uintptr(unsafe.Pointer(&emptyByte)) diff --git a/loader/funcdata_go117.go b/loader/funcdata_go117.go index 623283d09..1cae26898 100644 --- a/loader/funcdata_go117.go +++ b/loader/funcdata_go117.go @@ -330,7 +330,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte funcnametab, nameOffs := makeFuncnameTab(funcs) mod.funcnametab = funcnametab - // mmap() text and funcdata segements + // mmap() text and funcdata segments p := os.Getpagesize() size := int(rnd(int64(len(text)), int64(p))) addr := mmap(size) @@ -390,7 +390,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte pclnOffset: getOffsetOf(moduledata{}, "pclntable"), } - // sepecial case: gcdata and gcbss must by non-empty + // special case: gcdata and gcbss must by non-empty mod.gcdata = uintptr(unsafe.Pointer(&emptyByte)) mod.gcbss = uintptr(unsafe.Pointer(&emptyByte)) diff --git a/loader/funcdata_latest.go b/loader/funcdata_latest.go index b19fa6b7d..8b6018bdc 100644 --- a/loader/funcdata_latest.go +++ b/loader/funcdata_latest.go @@ -222,7 +222,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte funcnametab, nameOffs := makeFuncnameTab(funcs) mod.funcnametab = funcnametab - // mmap() text and funcdata segements + // mmap() text and funcdata segments p := os.Getpagesize() size := int(rnd(int64(len(text)), int64(p))) addr := mmap(size) @@ -283,7 +283,7 @@ func makeModuledata(name string, filenames []string, funcsp *[]Func, text []byte pclnOffset: getOffsetOf(moduledata{}, "pclntable"), } - // sepecial case: gcdata and gcbss must by non-empty + // special case: gcdata and gcbss must by non-empty mod.gcdata = uintptr(unsafe.Pointer(&emptyByte)) mod.gcbss = uintptr(unsafe.Pointer(&emptyByte)) diff --git a/native/atof_native.h b/native/atof_native.h index 629d0cc35..a6c4a62dd 100644 --- a/native/atof_native.h +++ b/native/atof_native.h @@ -18,7 +18,7 @@ #include "native.h" -/* decimical shift witout overflow, e.g. 9 << 61 overflow */ +/* decimical shift without overflow, e.g. 9 << 61 overflow */ #define MAX_SHIFT 60 /* Decimal represent the integer or float @@ -90,7 +90,7 @@ static always_inline void decimal_set(Decimal *d, const char *s, ssize_t len, ch d->d[d->nd] = s[i]; d->nd++; } else if (s[i] != '0') { - /* truncat the remaining digits */ + /* truncate the remaining digits */ d->trunc = 1; } } else if (s[i] == '.') { @@ -367,7 +367,7 @@ static always_inline int decimal_to_f64(Decimal *d, double *val) { /* Our range is [0.5,1) but floating point range is [1,2) */ exp2 --; - /* Minimum exp2 for doulbe is -1022. + /* Minimum exp2 for double is -1022. * If the exponent is smaller, move it up and * adjust d accordingly. */ diff --git a/native/html_escape.c b/native/html_escape.c index e6925d1b2..5d895471d 100644 --- a/native/html_escape.c +++ b/native/html_escape.c @@ -36,7 +36,7 @@ ssize_t html_escape(const char *sp, ssize_t nb, char *dp, ssize_t *dn) { break; } - /* mark cur postion */ + /* mark cur position */ cur = sp; /* check for \u2028 and \u2029, binary is \xe2\x80\xa8 and \xe2\x80\xa9 */ diff --git a/native/parse_with_padding.c b/native/parse_with_padding.c index 64f685751..4a6d21744 100644 --- a/native/parse_with_padding.c +++ b/native/parse_with_padding.c @@ -37,7 +37,7 @@ static const option _F_USE_NUMBER = 1; // types.B_USE_NUMBER static const option _F_VALIDATE_STR = 5; // types.B_VALIDATE_STRING static const option _F_ALLOW_CTL = 31; // types.B_ALLOW_CONTROL -// NOTE: only enbale these flags in sonic-rs. +// NOTE: only enable these flags in sonic-rs. static const option F_USE_NUMBER = 1 << _F_USE_NUMBER; static const option F_USE_INT64 = 1 << _F_USE_INT64; static const option F_VALIDATE_STRING = 1 << _F_VALIDATE_STR; @@ -636,7 +636,7 @@ static always_inline long parse_string_inplace(uint8_t** cur, bool* has_esc, uin return -SONIC_INVALID_ESCAPED_UTF; } - // check continous escaped char + // check continuous escaped char if (**cur == '\\') { goto escape; } @@ -739,7 +739,7 @@ static always_inline error_code parse_number(uint8_t** cur, parse_num* num, bool } if (**cur == '.') { - // skip continous zeros + // skip continuous zeros *cur += 1; uint8_t* dot_pos = *cur; should_digit(**cur); diff --git a/native/parsing.h b/native/parsing.h index f3f188574..fee32d6c7 100644 --- a/native/parsing.h +++ b/native/parsing.h @@ -423,7 +423,7 @@ static always_inline ssize_t memcchr_p32(const char *s, ssize_t nb, char *p) { _mm256_zeroupper(); #endif - /* initialze with '\\' */ + /* initialize with '\\' */ __m128i x; __m128i y; __m128i a = _mm_set1_epi8('\\'); diff --git a/native/scanning.h b/native/scanning.h index 96047baa1..b399eb45c 100644 --- a/native/scanning.h +++ b/native/scanning.h @@ -349,7 +349,7 @@ static always_inline int _mm256_get_mask(__m256i v, __m256i t) { return _mm256_movemask_epi8(_mm256_cmpeq_epi8(v, t)); } -// contrl char: 0x00 ~ 0x1F +// control char: 0x00 ~ 0x1F static always_inline int _mm256_cchars_mask(__m256i v) { __m256i e1 = _mm256_cmpgt_epi8 (v, _mm256_set1_epi8(-1)); __m256i e2 = _mm256_cmpgt_epi8 (v, _mm256_set1_epi8(31)); @@ -367,7 +367,7 @@ static always_inline int _mm_get_mask(__m128i v, __m128i t) { return _mm_movemask_epi8(_mm_cmpeq_epi8(v, t)); } -// contrl char: 0x00 ~ 0x1F +// control char: 0x00 ~ 0x1F static always_inline int _mm_cchars_mask(__m128i v) { __m128i e1 = _mm_cmpgt_epi8 (v, _mm_set1_epi8(-1)); __m128i e2 = _mm_cmpgt_epi8 (v, _mm_set1_epi8(31)); @@ -800,7 +800,7 @@ static always_inline double atof_fast(uint64_t man, int exp, int sgn, int trunc, static bool always_inline is_overflow(uint64_t man, int sgn, int exp10) { /* the former exp10 != 0 means man has overflowed - * the later euqals to man*sgn < INT64_MIN or > INT64_MAX */ + * the latter equals to man*sgn < INT64_MIN or > INT64_MAX */ return exp10 != 0 || ((man >> 63) == 1 && ((uint64_t)sgn & man) != (1ull << 63)); } diff --git a/native/utf8.h b/native/utf8.h index 73a988ca9..fe58b48fe 100644 --- a/native/utf8.h +++ b/native/utf8.h @@ -131,7 +131,7 @@ static always_inline long write_error(int pos, StateMachine *m, size_t msize) { return 0; } -// scalar code, error position should excesss 4096 +// scalar code, error position should excess 4096 static always_inline long validate_utf8_with_errors(const char *src, long len, long *p, StateMachine *m) { const char* start = src + *p; const char* end = src + len; @@ -437,14 +437,14 @@ static always_inline long validate_utf8_errors(const GoString* s) { return; } - // frist 64 bytes is ascii, next 64 bytes must be utf8 + // first 64 bytes is ascii, next 64 bytes must be utf8 if (likely(is_ascii(reducer1))) { checker->error = _mm256_or_si256(checker->error, checker->prev_incomplete); check64_utf(checker, start + 64); return; } - // frist 64 bytes has utf8, next 64 bytes + // first 64 bytes has utf8, next 64 bytes check64_utf(checker, start); if (unlikely(is_ascii(reducer2))) { checker->error = _mm256_or_si256(checker->error, checker->prev_incomplete); diff --git a/option/option.go b/option/option.go index 4d9965260..1ec6a8528 100644 --- a/option/option.go +++ b/option/option.go @@ -68,7 +68,7 @@ type CompileOption func(o *CompileOptions) // // For deep nested struct (depth exceeds MaxInlineDepth), // try to set more loops to completely compile, -// thus reduce JIT unstability in the first hit. +// thus reduce JIT instability in the first hit. func WithCompileRecursiveDepth(loop int) CompileOption { return func(o *CompileOptions) { if loop < 0 { diff --git a/scripts/bench.py b/scripts/bench.py index 41e1b5a08..206a9dd1a 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -49,7 +49,7 @@ def run_r(cmd): return data.decode("utf-8") def compare(args): - # detech current branch. + # detect current branch. # result = run_r("git branch") current_branch = run_s("git status | head -n1 | sed 's/On branch //'") # for br in result.split('\n'): @@ -58,14 +58,14 @@ def compare(args): # break if not current_branch: - print ("Failed to detech current branch") + print ("Failed to detect current branch") return None # get the current diff (fd, diff) = tempfile.mkstemp() run("git diff > %s"%diff) - # early return if currrent is main branch. + # early return if current is main branch. print ("Current branch: %s"%(current_branch)) if current_branch == "main": print ("Cannot compare at the main branch.Please build a new branch") diff --git a/scripts/build-x86.sh b/scripts/build-x86.sh index 4a0725bdd..030e7a907 100755 --- a/scripts/build-x86.sh +++ b/scripts/build-x86.sh @@ -60,7 +60,7 @@ for arc in "${CPU_ARCS[@]}"; do # should check the output assembly files if ! grep -rq ${CHECK_ARCS[$i]} $out_dir; then - echo "compiled instructions is incorret, pleas check again" + echo "compiled instructions is incorrect, please check again" exit 1 fi diff --git a/tools/asm2arm/arm.py b/tools/asm2arm/arm.py index 14b6164de..46effcd71 100644 --- a/tools/asm2arm/arm.py +++ b/tools/asm2arm/arm.py @@ -477,7 +477,7 @@ def encode(buf: bytes, comments: str = '') -> str: # return '\n\t'.join(r) if (n % 4 != 0): - raise RuntimeError("Unkown instruction which not encoding 4 bytes: %s " % comments, buf) + raise RuntimeError("Unknown instruction which not encoding 4 bytes: %s " % comments, buf) while i < n - 3: r.append('WORD $0x%08x' % int.from_bytes(buf[i:i + 4], 'little')) @@ -567,7 +567,7 @@ def optimize(self): self.out.append((self.pc - self.entry, self.sp)) # sort by pc self.out.sort(key=lambda x: x[0]) - # NOTICE: first pair {1, 0} to be compitable with golang + # NOTICE: first pair {1, 0} to be compatible with golang tmp = [(1, 0)] lpc, lsp = 0, -1 for pc, sp in self.out: @@ -927,7 +927,7 @@ def parse(cls, src: str) -> 'Command': # invalid hexadecimal character elif esc in (ESC_HEX0, ESC_HEX1): - raise SyntaxError('invalid hexdecimal character: ' + repr(nch)) + raise SyntaxError('invalid hexadecimal character: ' + repr(nch)) # octal escape characters elif esc in (ESC_OCT1, ESC_OCT2) and nch.lower() in string.octdigits: @@ -1329,7 +1329,7 @@ def if_all_IntInstr_then_2_RawInstr(self): if instr_size == 8 or instr_size == 4: return - # All instrs are IntInstr, golang asm only suuport WORD and DWORD for arm. We need + # All instrs are IntInstr, golang asm only support WORD and DWORD for arm. We need # combine them as 4-bytes RawInstr and align block nb = [] # new body raw_buf = []; @@ -1374,7 +1374,7 @@ def jump_to(self, block: 'BasicBlock'): block.prevs.append(self) @classmethod - def annonymous(cls) -> 'BasicBlock': + def anonymous(cls) -> 'BasicBlock': return cls('// bb.%d' % Counter.next(), weak = False) CLANG_JUMPTABLE_LABLE = 'LJTI' @@ -1392,7 +1392,7 @@ def __init__(self): self.dead = False self.labels = {} self.export = False - self.blocks = [BasicBlock.annonymous()] + self.blocks = [BasicBlock.anonymous()] self.jmptabs = {} self.funcs = {} self.bsmap_ = {} @@ -1451,7 +1451,7 @@ def _kill(self, name: str): def _split(self, jmp: BasicBlock): self.jump = True - link = BasicBlock.annonymous() + link = BasicBlock.anonymous() self.labels[link.name] = link self.block.link_to(link) self.block.jump_to(jmp) @@ -1505,7 +1505,7 @@ def _alloc_instr(self, instr: Instruction): else: self.block.body.append(BranchInstr(instr)) - # it seems to not be able to specify stack aligment inside the Go ASM so we + # it seems to not be able to specify stack alignment inside the Go ASM so we # need to replace the aligned instructions with unaligned one if either of it's # operand is an RBP relative addressing memory operand @@ -1645,7 +1645,7 @@ def _trace_instructions(self, bb: BasicBlock, pcsp: Pcsp) -> Tuple[int, bool]: elif name == 'str': diff = -self._mk_align(operands[3]) else: - raise RuntimeError("An instruction adjsut sp but bot processed: %s" % ins.instr.asm_code) + raise RuntimeError("An instruction adjust sp but bot processed: %s" % ins.instr.asm_code) cursp += diff @@ -2092,7 +2092,7 @@ def _declare_function(self, name: str, proto: Prototype): # self.out.append('\tMOVD R29, -8(RSP)') # self.out.append('\tSUB $8, RSP, R29') - # intialize all the arguments + # initialize all the arguments for arg in proto.args: offs += arg.size op, reg = REG_MAP[arg.creg.reg] diff --git a/unquote/unquote.go b/unquote/unquote.go index d81406b2a..29b2fcde8 100644 --- a/unquote/unquote.go +++ b/unquote/unquote.go @@ -25,7 +25,7 @@ import ( `github.com/bytedance/sonic/internal/rt` ) -// String unescapes a escaped string (not including `"` at begining and end) +// String unescapes an escaped string (not including `"` at beginning and end) // It validates invalid UTF8 and replace with `\ufffd` func String(s string) (ret string, err types.ParsingError) { mm := make([]byte, 0, len(s)) @@ -43,7 +43,7 @@ func IntoBytes(s string, m *[]byte) types.ParsingError { } } -// String unescapes a escaped string (not including `"` at begining and end) +// String unescapes an escaped string (not including `"` at beginning and end) // - replace enables replacing invalid utf8 escaped char with `\uffd` func _String(s string, replace bool) (ret string, err error) { mm := make([]byte, 0, len(s)) diff --git a/utf8/utf8.go b/utf8/utf8.go index 573fe2f5b..9d8bcc958 100644 --- a/utf8/utf8.go +++ b/utf8/utf8.go @@ -29,7 +29,7 @@ func CorrectWith(dst []byte, src []byte, repl string) []byte { sstr := rt.Mem2Str(src) sidx := 0 - /* state machine records the invalid postions */ + /* state machine records the invalid positions */ m := types.NewStateMachine() m.Sp = 0 // invalid utf8 numbers