export function slicePathTurbo()

in packages/layers/flyline/src/util.ts [259:303]


export function slicePathTurbo(path, offset, length) {
	// window.counter ++
	const start = offset >= 0 ? offset : 0
	const end = offset + length // end 超了的话slice会自己处理, 长度不会变得更长
	let re = path.slice(start, end)

	// path     0-1-2-3-4-5-6
	// slice  0-0-1-2-3
	if (offset < 0) {
		let buf = re.slice(0, 3)
		buf = buf.length > 2 ? buf : [0, 0, 0]
		let len = 0 - offset
		if (end < 0) {
			// path              0-1-2-3-4-5-6
			// slice  0-0-0-0-0
			len = length
		}
		const head: any[] = []
		for (let i = 0; i < len; i += 3) {
			// head = head.concat(buf) // benchmark性能更高,但是频繁GC
			head.push(...buf)
		}
		re = head.concat(re)
		// re.unshift(...head)
	}

	// path     0-1-2-3-4-5-6
	// slice            4-5-6-6-6
	if (end > path.length) {
		let buf = re.slice(-3)
		buf = buf.length > 2 ? buf : [0, 0, 0]
		let len = end - path.length
		if (offset > path.length) {
			// path   0-1-2-3-4-5-6
			// slice                6-6-6-6-6
			len = length
		}
		for (let i = 0; i < len; i += 3) {
			// re = re.concat(buf) // benchmark性能更高,但是频繁GC
			re.push(...buf)
		}
	}

	return re
}