##// END OF EJS Templates
rhg: in path_encode add a DestArr type...
Arseniy Alekseyev -
r51055:5ce53ff6 default
parent child Browse files
Show More
@@ -45,6 +45,38 b' fn inset(bitset: &[u32; 8], c: u8) -> bo'
45 bitset[(c as usize) >> 5] & (1 << (c & 31)) != 0
45 bitset[(c as usize) >> 5] & (1 << (c & 31)) != 0
46 }
46 }
47
47
48 const MAXENCODE: usize = 4096 * 4;
49
50 struct DestArr {
51 buf: [u8; MAXENCODE],
52 pub len: usize,
53 }
54
55 impl DestArr {
56 pub fn create() -> Self {
57 DestArr {
58 buf: [0; MAXENCODE],
59 len: 0,
60 }
61 }
62
63 pub fn contents(&self) -> &[u8] {
64 &self.buf[..self.len]
65 }
66 }
67
68 impl Sink for DestArr {
69 fn write_byte(&mut self, c: u8) {
70 self.buf[self.len] = c;
71 self.len += 1;
72 }
73
74 fn write_bytes(&mut self, src: &[u8]) {
75 self.buf[self.len..self.len + src.len()].copy_from_slice(src);
76 self.len += src.len();
77 }
78 }
79
48 struct Dest<'a> {
80 struct Dest<'a> {
49 dest: Option<&'a mut [u8]>,
81 dest: Option<&'a mut [u8]>,
50 pub len: usize,
82 pub len: usize,
@@ -567,26 +599,19 b' fn hash_mangle(src: &[u8], sha: &[u8]) -'
567 }
599 }
568 }
600 }
569
601
570 const MAXENCODE: usize = 4096 * 4;
571 fn hash_encode(src: &[u8]) -> Vec<u8> {
602 fn hash_encode(src: &[u8]) -> Vec<u8> {
572 let dired = &mut [0; MAXENCODE];
603 let mut dired = DestArr::create();
573 let mut dired_dest = Dest::create(dired);
604 let mut lowered = DestArr::create();
574 let lowered = &mut [0; MAXENCODE];
605 let mut auxed = DestArr::create();
575 let mut lowered_dest = Dest::create(lowered);
576 let auxed = &mut [0; MAXENCODE];
577 let mut auxed_dest = Dest::create(auxed);
578 let baselen = (src.len() - 5) * 3;
606 let baselen = (src.len() - 5) * 3;
579 if baselen >= MAXENCODE {
607 if baselen >= MAXENCODE {
580 panic!("path_encode::hash_encore: string too long: {}", baselen)
608 panic!("path_encode::hash_encore: string too long: {}", baselen)
581 };
609 };
582 encode_dir(&mut dired_dest, src);
610 encode_dir(&mut dired, src);
583 let dirlen = dired_dest.len;
611 let sha = Sha1::digest(dired.contents());
584 let sha = Sha1::digest(&dired[..dirlen]);
612 lower_encode(&mut lowered, &dired.contents()[5..]);
585 lower_encode(&mut lowered_dest, &dired[..dirlen][5..]);
613 aux_encode(&mut auxed, lowered.contents());
586 let lowerlen = lowered_dest.len;
614 hash_mangle(auxed.contents(), &sha)
587 aux_encode(&mut auxed_dest, &lowered[..lowerlen]);
588 let auxlen = auxed_dest.len;
589 hash_mangle(&auxed[..auxlen], &sha)
590 }
615 }
591
616
592 pub fn path_encode(path: &[u8]) -> Vec<u8> {
617 pub fn path_encode(path: &[u8]) -> Vec<u8> {
General Comments 0
You need to be logged in to leave comments. Login now