Show More
@@ -77,29 +77,17 b' impl<const N: usize> Sink for DestArr<N>' | |||
|
77 | 77 | } |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | struct VecDest { | |
|
81 | buf: Vec<u8>, | |
|
82 | } | |
|
83 | ||
|
84 | 80 | struct MeasureDest { |
|
85 | 81 | pub len: usize, |
|
86 | 82 | } |
|
87 | 83 | |
|
88 | impl VecDest { | |
|
89 | pub fn create(capacity : usize) -> Self { | |
|
90 | Self { | |
|
91 | buf: Vec::with_capacity(capacity), | |
|
92 | } | |
|
93 | } | |
|
94 | } | |
|
95 | ||
|
96 | impl Sink for VecDest { | |
|
84 | impl Sink for Vec<u8> { | |
|
97 | 85 | fn write_byte(&mut self, c: u8) { |
|
98 |
self |
|
|
86 | self.push(c) | |
|
99 | 87 | } |
|
100 | 88 | |
|
101 | 89 | fn write_bytes(&mut self, src: &[u8]) { |
|
102 |
self |
|
|
90 | self.extend_from_slice(src) | |
|
103 | 91 | } |
|
104 | 92 | } |
|
105 | 93 | |
@@ -544,13 +532,13 b' fn hash_mangle(src: &[u8], sha: &[u8]) -' | |||
|
544 | 532 | src[s..].iter().rposition(|b| *b == b'.').map(|i| i + s) |
|
545 | 533 | }; |
|
546 | 534 | |
|
547 |
let mut dest |
|
|
535 | let mut dest = Vec::with_capacity(MAXSTOREPATHLEN); | |
|
548 | 536 | dest.write_bytes(b"dh/"); |
|
549 | 537 | |
|
550 | 538 | if let Some(last_slash) = last_slash { |
|
551 | 539 | for slice in src[..last_slash].split(|b| *b == b'/') { |
|
552 | 540 | let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)]; |
|
553 |
if dest |
|
|
541 | if dest.len() + slice.len() > maxshortdirslen + 3 { | |
|
554 | 542 | break; |
|
555 | 543 | } else { |
|
556 | 544 | dest.write_bytes(slice); |
@@ -559,7 +547,7 b' fn hash_mangle(src: &[u8], sha: &[u8]) -' | |||
|
559 | 547 | } |
|
560 | 548 | } |
|
561 | 549 | |
|
562 |
let used = dest |
|
|
550 | let used = dest.len() + 40 + { | |
|
563 | 551 | if let Some(l) = last_dot { |
|
564 | 552 | src.len() - l |
|
565 | 553 | } else { |
@@ -588,7 +576,7 b' fn hash_mangle(src: &[u8], sha: &[u8]) -' | |||
|
588 | 576 | if let Some(l) = last_dot { |
|
589 | 577 | dest.write_bytes(&src[l..]); |
|
590 | 578 | } |
|
591 |
dest |
|
|
579 | dest | |
|
592 | 580 | } |
|
593 | 581 | |
|
594 | 582 | fn hash_encode(src: &[u8]) -> Vec<u8> { |
@@ -618,10 +606,10 b' pub fn path_encode(path: &[u8]) -> Vec<u' | |||
|
618 | 606 | if newlen == path.len() { |
|
619 | 607 | path.to_vec() |
|
620 | 608 | } else { |
|
621 |
let mut dest = Vec |
|
|
609 | let mut dest = Vec::with_capacity(newlen); | |
|
622 | 610 | basic_encode(&mut dest, path); |
|
623 |
assert!(dest |
|
|
624 |
dest |
|
|
611 | assert!(dest.len() == newlen); | |
|
612 | dest | |
|
625 | 613 | } |
|
626 | 614 | } else { |
|
627 | 615 | hash_encode(path) |
General Comments 0
You need to be logged in to leave comments.
Login now