ソースを参照

codec: rename decReaderSwitch to decRd and encWriterSwitch to encWr

Ugorji Nwoke 6 年 前
コミット
47cabf7243
10 ファイル変更78 行追加78 行削除
  1. 2 2
      codec/binc.go
  2. 2 2
      codec/cbor.go
  3. 8 8
      codec/decode.go
  4. 7 7
      codec/encode.go
  5. 1 1
      codec/helper.go
  6. 2 2
      codec/json.go
  7. 2 2
      codec/msgpack.go
  8. 32 32
      codec/reader.go
  9. 2 2
      codec/simple.go
  10. 20 20
      codec/writer.go

+ 2 - 2
codec/binc.go

@@ -102,7 +102,7 @@ type bincEncDriver struct {
 	encDriverNoopContainerWriter
 	e *Encoder
 	h *BincHandle
-	w *encWriterSwitch
+	w *encWr
 	m map[string]uint16 // symbols
 	b [16]byte          // scratch, used for encoding numbers - bigendian style
 	s uint16            // symbols sequencer
@@ -388,7 +388,7 @@ type bincDecDriver struct {
 
 	d      *Decoder
 	h      *BincHandle
-	r      *decReaderSwitch
+	r      *decRd
 	br     bool // bytes reader
 	bdRead bool
 	bd     byte

+ 2 - 2
codec/cbor.go

@@ -116,7 +116,7 @@ type cborEncDriver struct {
 	noBuiltInTypes
 	encDriverNoopContainerWriter
 	e *Encoder
-	w *encWriterSwitch
+	w *encWr
 	h *CborHandle
 	x [8]byte
 	// _ [3]uint64 // padding
@@ -298,7 +298,7 @@ func (e *cborEncDriver) encStringBytesS(bb byte, v string) {
 type cborDecDriver struct {
 	d      *Decoder
 	h      *CborHandle
-	r      *decReaderSwitch
+	r      *decRd
 	br     bool // bytes reader
 	bdRead bool
 	bd     byte

+ 8 - 8
codec/decode.go

@@ -1336,7 +1336,7 @@ type Decoder struct {
 
 	// NOTE: Decoder shouldn't call its read methods,
 	// as the handler MAY need to do some coordination.
-	// r *decReaderSwitch
+	// r *decRd
 
 	// bi *bufioDecReader
 	// cache the mapTypeId and sliceTypeId for faster comparisons
@@ -1348,7 +1348,7 @@ type Decoder struct {
 	hh   Handle
 
 	// ---- cpu cache line boundary?
-	decReaderSwitch
+	decRd
 
 	// ---- cpu cache line boundary?
 	n decNaked
@@ -1409,7 +1409,7 @@ func newDecoder(h Handle) *Decoder {
 	if useFinalizers {
 		runtime.SetFinalizer(d, (*Decoder).finalize)
 	}
-	// d.r = &d.decReaderSwitch
+	// d.r = &d.decRd
 	d.hh = h
 	d.be = h.isBinary()
 	// NOTE: do not initialize d.n here. It is lazily initialized in d.naked()
@@ -1431,12 +1431,12 @@ func newDecoder(h Handle) *Decoder {
 	return d
 }
 
-func (d *Decoder) r() *decReaderSwitch {
-	return &d.decReaderSwitch
+func (d *Decoder) r() *decRd {
+	return &d.decRd
 }
 
 func (d *Decoder) resetCommon() {
-	// d.r = &d.decReaderSwitch
+	// d.r = &d.decRd
 	d.d.reset()
 	d.err = nil
 	d.depth = 0
@@ -1640,7 +1640,7 @@ func (d *Decoder) mustDecode(v interface{}) {
 		d.d.atEndOfDecode()
 		// release
 		// if !d.h.ExplicitRelease {
-		// 	d.decReaderSwitch.release()
+		// 	d.decRd.release()
 		// 	// if d.jdec != nil {
 		// 	// 	d.jdec.release()
 		// 	// }
@@ -2189,7 +2189,7 @@ func (x decSliceHelper) ElemContainerState(index int) {
 	}
 }
 
-func decByteSlice(r *decReaderSwitch, clen, maxInitLen int, bs []byte) (bsOut []byte) {
+func decByteSlice(r *decRd, clen, maxInitLen int, bs []byte) (bsOut []byte) {
 	if clen == 0 {
 		return zeroByteSlice
 	}

+ 7 - 7
codec/encode.go

@@ -847,7 +847,7 @@ type Encoder struct {
 
 	// NOTE: Encoder shouldn't call it's write methods,
 	// as the handler MAY need to do some coordination.
-	// w *encWriterSwitch
+	// w *encWr
 
 	// bw *bufio.Writer
 	as encDriverAsis
@@ -857,7 +857,7 @@ type Encoder struct {
 	hh   Handle
 
 	// ---- cpu cache line boundary
-	encWriterSwitch
+	encWr
 
 	err error
 
@@ -906,19 +906,19 @@ func newEncoder(h Handle) *Encoder {
 	if useFinalizers {
 		runtime.SetFinalizer(e, (*Encoder).finalize)
 	}
-	// e.w = &e.encWriterSwitch
+	// e.w = &e.encWr
 	e.hh = h
 	e.esep = h.hasElemSeparators()
 
 	return e
 }
 
-func (e *Encoder) w() *encWriterSwitch {
-	return &e.encWriterSwitch
+func (e *Encoder) w() *encWr {
+	return &e.encWr
 }
 
 func (e *Encoder) resetCommon() {
-	// e.w = &e.encWriterSwitch
+	// e.w = &e.encWr
 	if e.e == nil || e.hh.recreateEncDriver(e.e) {
 		e.e = e.hh.newEncDriver(e)
 		e.as, e.isas = e.e.(encDriverAsis)
@@ -1502,7 +1502,7 @@ func (e *Encoder) sideEncode(v interface{}, bs *[]byte) {
 	e2.w().end()
 }
 
-func encStructFieldKey(encName string, ee encDriver, w *encWriterSwitch,
+func encStructFieldKey(encName string, ee encDriver, w *encWr,
 	keyType valueType, encNameAsciiAlphaNum bool, js bool) {
 	var m must
 	// use if-else-if, not switch (which compiles to binary-search)

+ 1 - 1
codec/helper.go

@@ -1205,7 +1205,7 @@ func (noElemSeparators) recreateEncDriver(e encDriver) (v bool) { return }
 // Users must already slice the x completely, because we will not reslice.
 type bigenHelper struct {
 	x []byte // must be correctly sliced to appropriate len. slicing is a cost.
-	w *encWriterSwitch
+	w *encWr
 }
 
 func (z bigenHelper) writeUint16(v uint16) {

+ 2 - 2
codec/json.go

@@ -348,7 +348,7 @@ func (e *jsonEncDriverGeneric) EncodeUint(v uint64) {
 
 type jsonEncDriver struct {
 	noBuiltInTypes
-	w *encWriterSwitch
+	w *encWr
 	e *Encoder
 	h *JsonHandle
 
@@ -593,7 +593,7 @@ type jsonDecDriver struct {
 	noBuiltInTypes
 	d *Decoder
 	h *JsonHandle
-	r *decReaderSwitch
+	r *decRd
 
 	tok  uint8   // used to store the token read right after skipWhiteSpace
 	fnil bool    // found null

+ 2 - 2
codec/msgpack.go

@@ -201,7 +201,7 @@ type msgpackEncDriver struct {
 	encDriverNoopContainerWriter
 	// encNoSeparator
 	e *Encoder
-	w *encWriterSwitch
+	w *encWr
 	h *MsgpackHandle
 	x [8]byte
 	// _ [3]uint64 // padding
@@ -425,7 +425,7 @@ func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) {
 
 type msgpackDecDriver struct {
 	d *Decoder
-	r *decReaderSwitch
+	r *decRd
 	h *MsgpackHandle
 	// b      [scratchByteArrayLen]byte
 	bd     byte

+ 32 - 32
codec/reader.go

@@ -10,7 +10,7 @@ import "io"
 // decReader abstracts the reading source, allowing implementations that can
 // read from an io.Reader or directly off a byte slice with zero-copying.
 //
-// Deprecated: Use decReaderSwitch instead.
+// Deprecated: Use decRd instead.
 type decReader interface {
 	unreadn1()
 	// readx will use the implementation scratch buffer if possible i.e. n < len(scratchbuf), OR
@@ -970,7 +970,7 @@ func (z *bytesDecReader) stopTrack() (bs []byte) {
 
 // --------------
 
-type decReaderSwitch struct {
+type decRd struct {
 	esep     bool // has elem separators
 	mtr, str bool // whether maptype or slicetype are known types
 
@@ -990,7 +990,7 @@ type decReaderSwitch struct {
 // numread, track and stopTrack are always inlined, as they just check int fields, etc.
 
 /*
-func (z *decReaderSwitch) numread() int {
+func (z *decRd) numread() int {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.numread()
@@ -1000,7 +1000,7 @@ func (z *decReaderSwitch) numread() int {
 		return z.bi.numread()
 	}
 }
-func (z *decReaderSwitch) track() {
+func (z *decRd) track() {
 	switch z.typ {
 	case entryTypeBytes:
 		z.rb.track()
@@ -1010,7 +1010,7 @@ func (z *decReaderSwitch) track() {
 		z.bi.track()
 	}
 }
-func (z *decReaderSwitch) stopTrack() []byte {
+func (z *decRd) stopTrack() []byte {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.stopTrack()
@@ -1021,7 +1021,7 @@ func (z *decReaderSwitch) stopTrack() []byte {
 	}
 }
 
-func (z *decReaderSwitch) unreadn1() {
+func (z *decRd) unreadn1() {
 	switch z.typ {
 	case entryTypeBytes:
 		z.rb.unreadn1()
@@ -1031,7 +1031,7 @@ func (z *decReaderSwitch) unreadn1() {
 		z.bi.unreadn1()
 	}
 }
-func (z *decReaderSwitch) readx(n int) []byte {
+func (z *decRd) readx(n int) []byte {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.readx(n)
@@ -1041,7 +1041,7 @@ func (z *decReaderSwitch) readx(n int) []byte {
 		return z.bi.readx(n)
 	}
 }
-func (z *decReaderSwitch) readb(s []byte) {
+func (z *decRd) readb(s []byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		z.rb.readb(s)
@@ -1051,7 +1051,7 @@ func (z *decReaderSwitch) readb(s []byte) {
 		z.bi.readb(s)
 	}
 }
-func (z *decReaderSwitch) readn1() uint8 {
+func (z *decRd) readn1() uint8 {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.readn1()
@@ -1061,7 +1061,7 @@ func (z *decReaderSwitch) readn1() uint8 {
 		return z.bi.readn1()
 	}
 }
-func (z *decReaderSwitch) skip(accept *bitset256) (token byte) {
+func (z *decRd) skip(accept *bitset256) (token byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.skip(accept)
@@ -1071,7 +1071,7 @@ func (z *decReaderSwitch) skip(accept *bitset256) (token byte) {
 		return z.bi.skip(accept)
 	}
 }
-func (z *decReaderSwitch) readTo(accept *bitset256) (out []byte) {
+func (z *decRd) readTo(accept *bitset256) (out []byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.readTo(accept)
@@ -1081,7 +1081,7 @@ func (z *decReaderSwitch) readTo(accept *bitset256) (out []byte) {
 		return z.bi.readTo(accept)
 	}
 }
-func (z *decReaderSwitch) readUntil(stop byte) (out []byte) {
+func (z *decRd) readUntil(stop byte) (out []byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		return z.rb.readUntil(stop)
@@ -1099,11 +1099,11 @@ func (z *decReaderSwitch) readUntil(stop byte) (out []byte) {
 // Best to only do an if fast-path else block (so fast-path is inlined).
 // This is irrespective of inlineExtraCallCost set in $GOROOT/src/cmd/compile/internal/gc/inl.go
 //
-// In decReaderSwitch methods below, we delegate all IO functions into their own methods.
+// In decRd methods below, we delegate all IO functions into their own methods.
 // This allows for the inlining of the common path when z.bytes=true.
 // Go 1.12+ supports inlining methods with up to 1 inlined function (or 2 if no other constructs).
 
-// func (z *decReaderSwitch) release() {
+// func (z *decRd) release() {
 // 	if z.bytes {
 // 	} else if z.bufio {
 // 		z.bi.release()
@@ -1111,7 +1111,7 @@ func (z *decReaderSwitch) readUntil(stop byte) (out []byte) {
 // 		z.ri.release()
 // 	}
 // }
-func (z *decReaderSwitch) numread() uint {
+func (z *decRd) numread() uint {
 	if z.bytes {
 		return z.rb.numread()
 	} else if z.bufio {
@@ -1120,7 +1120,7 @@ func (z *decReaderSwitch) numread() uint {
 		return z.ri.numread()
 	}
 }
-func (z *decReaderSwitch) track() {
+func (z *decRd) track() {
 	if z.bytes {
 		z.rb.track()
 	} else if z.bufio {
@@ -1129,7 +1129,7 @@ func (z *decReaderSwitch) track() {
 		z.ri.track()
 	}
 }
-func (z *decReaderSwitch) stopTrack() []byte {
+func (z *decRd) stopTrack() []byte {
 	if z.bytes {
 		return z.rb.stopTrack()
 	} else if z.bufio {
@@ -1139,14 +1139,14 @@ func (z *decReaderSwitch) stopTrack() []byte {
 	}
 }
 
-// func (z *decReaderSwitch) unreadn1() {
+// func (z *decRd) unreadn1() {
 // 	if z.bytes {
 // 		z.rb.unreadn1()
 // 	} else {
 // 		z.unreadn1IO()
 // 	}
 // }
-// func (z *decReaderSwitch) unreadn1IO() {
+// func (z *decRd) unreadn1IO() {
 // 	if z.bufio {
 // 		z.bi.unreadn1()
 // 	} else {
@@ -1154,7 +1154,7 @@ func (z *decReaderSwitch) stopTrack() []byte {
 // 	}
 // }
 
-func (z *decReaderSwitch) unreadn1() {
+func (z *decRd) unreadn1() {
 	if z.bytes {
 		z.rb.unreadn1()
 	} else if z.bufio {
@@ -1164,20 +1164,20 @@ func (z *decReaderSwitch) unreadn1() {
 	}
 }
 
-func (z *decReaderSwitch) readx(n uint) []byte {
+func (z *decRd) readx(n uint) []byte {
 	if z.bytes {
 		return z.rb.readx(n)
 	}
 	return z.readxIO(n)
 }
-func (z *decReaderSwitch) readxIO(n uint) []byte {
+func (z *decRd) readxIO(n uint) []byte {
 	if z.bufio {
 		return z.bi.readx(n)
 	}
 	return z.ri.readx(n)
 }
 
-func (z *decReaderSwitch) readb(s []byte) {
+func (z *decRd) readb(s []byte) {
 	if z.bytes {
 		z.rb.readb(s)
 	} else {
@@ -1186,7 +1186,7 @@ func (z *decReaderSwitch) readb(s []byte) {
 }
 
 //go:noinline - fallback for io, ensures z.bytes path is inlined
-func (z *decReaderSwitch) readbIO(s []byte) {
+func (z *decRd) readbIO(s []byte) {
 	if z.bufio {
 		z.bi.readb(s)
 	} else {
@@ -1194,33 +1194,33 @@ func (z *decReaderSwitch) readbIO(s []byte) {
 	}
 }
 
-func (z *decReaderSwitch) readn1() uint8 {
+func (z *decRd) readn1() uint8 {
 	if z.bytes {
 		return z.rb.readn1()
 	}
 	return z.readn1IO()
 }
-func (z *decReaderSwitch) readn1IO() uint8 {
+func (z *decRd) readn1IO() uint8 {
 	if z.bufio {
 		return z.bi.readn1()
 	}
 	return z.ri.readn1()
 }
 
-func (z *decReaderSwitch) skip(accept *bitset256) (token byte) {
+func (z *decRd) skip(accept *bitset256) (token byte) {
 	if z.bytes {
 		return z.rb.skip(accept)
 	}
 	return z.skipIO(accept)
 }
-func (z *decReaderSwitch) skipIO(accept *bitset256) (token byte) {
+func (z *decRd) skipIO(accept *bitset256) (token byte) {
 	if z.bufio {
 		return z.bi.skip(accept)
 	}
 	return z.ri.skip(accept)
 }
 
-func (z *decReaderSwitch) readTo(accept *bitset256) (out []byte) {
+func (z *decRd) readTo(accept *bitset256) (out []byte) {
 	if z.bytes {
 		return z.rb.readTo(accept)
 	}
@@ -1228,20 +1228,20 @@ func (z *decReaderSwitch) readTo(accept *bitset256) (out []byte) {
 }
 
 //go:noinline - fallback for io, ensures z.bytes path is inlined
-func (z *decReaderSwitch) readToIO(accept *bitset256) (out []byte) {
+func (z *decRd) readToIO(accept *bitset256) (out []byte) {
 	if z.bufio {
 		return z.bi.readTo(accept)
 	}
 	return z.ri.readTo(accept)
 }
-func (z *decReaderSwitch) readUntil(stop byte) (out []byte) {
+func (z *decRd) readUntil(stop byte) (out []byte) {
 	if z.bytes {
 		return z.rb.readUntil(stop)
 	}
 	return z.readUntilIO(stop)
 }
 
-func (z *decReaderSwitch) readUntilIO(stop byte) (out []byte) {
+func (z *decRd) readUntilIO(stop byte) (out []byte) {
 	if z.bufio {
 		return z.bi.readUntil(stop)
 	}

+ 2 - 2
codec/simple.go

@@ -36,7 +36,7 @@ type simpleEncDriver struct {
 	// encNoSeparator
 	e *Encoder
 	h *SimpleHandle
-	w *encWriterSwitch
+	w *encWr
 	b [8]byte
 	// c containerState
 	// encDriverTrackContainerWriter
@@ -207,7 +207,7 @@ func (e *simpleEncDriver) EncodeTime(t time.Time) {
 type simpleDecDriver struct {
 	d      *Decoder
 	h      *SimpleHandle
-	r      *decReaderSwitch
+	r      *decRd
 	bdRead bool
 	bd     byte
 	br     bool // a bytes reader?

+ 20 - 20
codec/writer.go

@@ -10,7 +10,7 @@ import "io"
 // encWriter abstracts writing to a byte array or to an io.Writer.
 //
 //
-// Deprecated: Use encWriterSwitch instead.
+// Deprecated: Use encWr instead.
 type encWriter interface {
 	writeb([]byte)
 	writestr(string)
@@ -108,7 +108,7 @@ func (z *ioEncWriter) writen2(b1, b2 byte) {
 // 	}
 // }
 
-//go:noinline - so *encWriterSwitch.XXX has the bytesEncAppender.XXX inlined
+//go:noinline - so *encWr.XXX has the bytesEncAppender.XXX inlined
 func (z *ioEncWriter) end() {
 	if z.fw != nil {
 		if err := z.fw.Flush(); err != nil {
@@ -325,7 +325,7 @@ func (z *bytesEncAppender) reset(in []byte, out *[]byte) {
 
 // --------------------------------------------------
 
-type encWriterSwitch struct {
+type encWr struct {
 	esep  bool // whether it has elem separators
 	bytes bool // encoding to []byte
 	isas  bool // whether e.as != nil
@@ -345,49 +345,49 @@ type encWriterSwitch struct {
 	// typ  entryType
 }
 
-func (z *encWriterSwitch) writeb(s []byte) {
+func (z *encWr) writeb(s []byte) {
 	if z.bytes {
 		z.wb.writeb(s)
 	} else {
 		z.wf.writeb(s)
 	}
 }
-func (z *encWriterSwitch) writeqstr(s string) {
+func (z *encWr) writeqstr(s string) {
 	if z.bytes {
 		z.wb.writeqstr(s)
 	} else {
 		z.wf.writeqstr(s)
 	}
 }
-func (z *encWriterSwitch) writestr(s string) {
+func (z *encWr) writestr(s string) {
 	if z.bytes {
 		z.wb.writestr(s)
 	} else {
 		z.wf.writestr(s)
 	}
 }
-func (z *encWriterSwitch) writen1(b1 byte) {
+func (z *encWr) writen1(b1 byte) {
 	if z.bytes {
 		z.wb.writen1(b1)
 	} else {
 		z.wf.writen1(b1)
 	}
 }
-func (z *encWriterSwitch) writen2(b1, b2 byte) {
+func (z *encWr) writen2(b1, b2 byte) {
 	if z.bytes {
 		z.wb.writen2(b1, b2)
 	} else {
 		z.wf.writen2(b1, b2)
 	}
 }
-func (z *encWriterSwitch) endErr() error {
+func (z *encWr) endErr() error {
 	if z.bytes {
 		return z.wb.endErr()
 	}
 	return z.wf.endErr()
 }
 
-func (z *encWriterSwitch) end() {
+func (z *encWr) end() {
 	if err := z.endErr(); err != nil {
 		panic(err)
 	}
@@ -396,7 +396,7 @@ func (z *encWriterSwitch) end() {
 /*
 
 // ------------------------------------------
-func (z *encWriterSwitch) writeb(s []byte) {
+func (z *encWr) writeb(s []byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		z.wb.writeb(s)
@@ -406,7 +406,7 @@ func (z *encWriterSwitch) writeb(s []byte) {
 		z.wf.writeb(s)
 	}
 }
-func (z *encWriterSwitch) writestr(s string) {
+func (z *encWr) writestr(s string) {
 	switch z.typ {
 	case entryTypeBytes:
 		z.wb.writestr(s)
@@ -416,7 +416,7 @@ func (z *encWriterSwitch) writestr(s string) {
 		z.wf.writestr(s)
 	}
 }
-func (z *encWriterSwitch) writen1(b1 byte) {
+func (z *encWr) writen1(b1 byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		z.wb.writen1(b1)
@@ -426,7 +426,7 @@ func (z *encWriterSwitch) writen1(b1 byte) {
 		z.wf.writen1(b1)
 	}
 }
-func (z *encWriterSwitch) writen2(b1, b2 byte) {
+func (z *encWr) writen2(b1, b2 byte) {
 	switch z.typ {
 	case entryTypeBytes:
 		z.wb.writen2(b1, b2)
@@ -436,7 +436,7 @@ func (z *encWriterSwitch) writen2(b1, b2 byte) {
 		z.wf.writen2(b1, b2)
 	}
 }
-func (z *encWriterSwitch) end() {
+func (z *encWr) end() {
 	switch z.typ {
 	case entryTypeBytes:
 		z.wb.end()
@@ -448,35 +448,35 @@ func (z *encWriterSwitch) end() {
 }
 
 // ------------------------------------------
-func (z *encWriterSwitch) writeb(s []byte) {
+func (z *encWr) writeb(s []byte) {
 	if z.bytes {
 		z.wb.writeb(s)
 	} else {
 		z.wi.writeb(s)
 	}
 }
-func (z *encWriterSwitch) writestr(s string) {
+func (z *encWr) writestr(s string) {
 	if z.bytes {
 		z.wb.writestr(s)
 	} else {
 		z.wi.writestr(s)
 	}
 }
-func (z *encWriterSwitch) writen1(b1 byte) {
+func (z *encWr) writen1(b1 byte) {
 	if z.bytes {
 		z.wb.writen1(b1)
 	} else {
 		z.wi.writen1(b1)
 	}
 }
-func (z *encWriterSwitch) writen2(b1, b2 byte) {
+func (z *encWr) writen2(b1, b2 byte) {
 	if z.bytes {
 		z.wb.writen2(b1, b2)
 	} else {
 		z.wi.writen2(b1, b2)
 	}
 }
-func (z *encWriterSwitch) end() {
+func (z *encWr) end() {
 	if z.bytes {
 		z.wb.end()
 	} else {