/// Generate a vector hash for the name string, weighting early over
/// later characters. We want to pick the same colors for function
/// names across different flame graphs.
Generate a vector hash for the name string, weighting early over
later characters. We want to pick the same colors for function
names across different flame graphs.
Generate a vector hash for the name string weighting early over later characters . We want to pick the same colors for function names across different flame graphs .
fn namehash<I: Iterator<Item = u8>>(mut name: I) -> f32 {
    let mut namehash_variables = NamehashVariables::init();
    let mut module_name_found = false;
    // The original Perl regex is: $name =~ s/.(.*?)`//;
    // Ie. we want to remove everything before the first '`'. If '`' is the first character,
    // we remove everything before the second '`'. If there is no '`', we keep everything.
    // This becomes tricky because we want to compute the hash and do the potential deletion
    // ine one pass only.
    // So, we start computing the hash and we check for '`' after the first character.
    // If we find '`' before the end of the computation (3 characters), we stop the computation.
    // If the computation finishes normally, we search for the first next '`'.
    // After that, either we have found a '`' (end of prefix), and we need to compute the hash from there,
    // or there is no '`' in the iterator and we have the hash computed!
    // In the Perl implementation, the hash was computed while `modulo > 12`, which means 3 iterations
    // maximum because modulo is initialized at 10.
    match name.next() {
        None => return namehash_variables.result(),
        Some(first_char) => namehash_variables.update(first_char),
    }
    for character in name.by_ref().take(2) {
        if character == b'`' {
            module_name_found = true;
            break;
        }
        namehash_variables.update(character);
    }
    module_name_found = module_name_found || name.any(|c| c == b'`');
    if module_name_found {
        namehash_variables = NamehashVariables::init();
        for character in name.take(3) {
            namehash_variables.update(character)
        }
    }
    namehash_variables.result()
}
fn namehash < I : Iterator < Item = u8 > > ( mut name : I ) -> f32 { let mut namehash_variables = NamehashVariables :: init ( ) ; let mut module_name_found = false ; // The original Perl regex is: $name =~ s/.(.*?)`//; // Ie. we want to remove everything before the first '`'. If '`' is the first character, // we remove everything before the second '`'. If there is no '`', we keep everything. // This becomes tricky because we want to compute the hash and do the potential deletion // ine one pass only. // So, we start computing the hash and we check for '`' after the first character. // If we find '`' before the end of the computation (3 characters), we stop the computation. // If the computation finishes normally, we search for the first next '`'. // After that, either we have found a '`' (end of prefix), and we need to compute the hash from there, // or there is no '`' in the iterator and we have the hash computed! // In the Perl implementation, the hash was computed while `modulo > 12`, which means 3 iterations // maximum because modulo is initialized at 10. match name . next ( ) { None => return namehash_variables . result ( ) , Some ( first_char ) => namehash_variables . update ( first_char ) , } for character in name . by_ref ( ) . take ( 2 ) { if character == b'`' { module_name_found = true ; break ; } namehash_variables . update ( character ) ; } module_name_found = module_name_found || name . any ( | c | c == b'`' ) ; if module_name_found { namehash_variables = NamehashVariables :: init ( ) ; for character in name . take ( 3 ) { namehash_variables . update ( character ) } } namehash_variables . result ( ) }
Generate a vector hash for the name string, weighting early over
later characters.
Generate a vector hash for the name string weighting early over later characters .
name
I