mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 16:57:08 +00:00
refactor: optimize length handling
This commit is contained in:
parent
5a8bd5e79e
commit
37107ac08d
@ -52,13 +52,14 @@ func (r *Rewriter) buildReplacement(srcAddr, dstAddr string, originalUA string,
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Adjust to the exact length needed
|
// Adjust to the exact length needed
|
||||||
if len(newUA) >= n {
|
newUALen := len(newUA)
|
||||||
|
if newUALen >= n {
|
||||||
return []byte(newUA[:n])
|
return []byte(newUA[:n])
|
||||||
}
|
}
|
||||||
out := make([]byte, n)
|
out := make([]byte, n)
|
||||||
copy(out, newUA)
|
copy(out, newUA)
|
||||||
// Pad with spaces if newUA is shorter than needed
|
// Pad with spaces if newUA is shorter than needed
|
||||||
for i := len(newUA); i < n; i++ {
|
for i := newUALen; i < n; i++ {
|
||||||
out[i] = ' '
|
out[i] = ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user