You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.9 KiB
51 lines
1.9 KiB
#!perl
|
|
|
|
print `p4 edit ../public/tier1/utlstringtoken_generated_contructors.h`;
|
|
|
|
open( FOUT, ">../public/tier1/utlstringtoken_generated_contructors.h" ) || die "cant open output file";
|
|
|
|
print FOUT "//===== Copyright © 1996-2009, Valve Corporation, All rights reserved. ======//\n";
|
|
print FOUT "//\n";
|
|
print FOUT "// Purpose: inlines for compile-time hashing of constant strings\n";
|
|
print FOUT "//\n";
|
|
print FOUT "// $NoKeywords: \$\n";
|
|
print FOUT "//\n";
|
|
print FOUT "//===========================================================================//\n";
|
|
print FOUT "// DO NOT EDIT THIS FILE - IT IS GENERATED BY RUNNING GENERATE_CONSTRUCTORS.PL\n\n";
|
|
|
|
print FOUT "#define TOLOWERU( c ) ( ( uint32 ) ( ( ( c >= 'A' ) && ( c <= 'Z' ) )? c + 32 : c ) )\n";
|
|
|
|
|
|
# generate for lengths 1 to 30
|
|
for( $i = 1; $i < 30; $i++ )
|
|
{
|
|
$len = $i - 1;
|
|
print FOUT "FORCEINLINE CUtlStringToken( const char ( \&str )[$i] )\n{\n";
|
|
print FOUT "\tconst uint32 m = 0x5bd1e995;\n";
|
|
print FOUT "\tuint32 h = STRINGTOKEN_MURMURHASH_SEED ^ $len;\n";
|
|
$curpos = 0;
|
|
print FOUT "\tuint32 k;\n" if ( $len >= 4 );
|
|
print FOUT "\tconst int r = 24;\n" if ( $len >= 4 );
|
|
while( $len >= 4)
|
|
{
|
|
print FOUT "\tk = TOLOWERU( str[ $curpos ] ) + ( TOLOWERU( str[ $curpos + 1 ] ) << 8 ) + ( TOLOWERU( str[ $curpos + 2 ] ) << 16 ) +";
|
|
print FOUT "( TOLOWERU( str[ $curpos + 3 ] ) << 24 );\n";
|
|
print FOUT "\tk *= m;\n";
|
|
print FOUT "\tk ^= k >> r;\n";
|
|
print FOUT "\tk *= m;\n";
|
|
print FOUT "\th *= m;\n";
|
|
print FOUT "\th ^= k;\n";
|
|
$curpos += 4;
|
|
$len -= 4;
|
|
}
|
|
|
|
print FOUT "\th ^= TOLOWERU( str[ $curpos + 2 ] ) << 16;\n" if ( $len >= 3 );
|
|
print FOUT "\th ^= TOLOWERU( str[ $curpos + 1 ] ) << 8;\n" if ( $len >= 2 );
|
|
print FOUT "\th ^= TOLOWERU( str[ $curpos + 0 ] );\n" if ( $len >= 1 );
|
|
print FOUT "\th *= m;\n" if ( $len >= 1 );
|
|
print FOUT "\th ^= h >> 13;\n";
|
|
print FOUT "\th *= m;\n";
|
|
print FOUT "\th ^= h >> 15;\n";
|
|
print FOUT "\tm_nHashCode = h;\n}\n\n";
|
|
}
|
|
|