浏览代码

Add a comment about forwardCopy semantics.

Nigel Tao 9 年之前
父节点
当前提交
9eb9b0a693
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      decode.go

+ 5 - 0
decode.go

@@ -127,6 +127,11 @@ func Decode(dst, src []byte) ([]byte, error) {
 		if offset <= 0 || d < offset || length > len(dst)-d {
 			return nil, ErrCorrupt
 		}
+		// Copy from an earlier sub-slice of dst to a later sub-slice. Unlike
+		// the built-in copy function, this byte-by-byte copy always runs
+		// forwards, even if the slices overlap. Conceptually, this is:
+		//
+		// d += forwardCopy(dst[d:d+length], dst[d-offset:])
 		for end := d + length; d != end; d++ {
 			dst[d] = dst[d-offset]
 		}