Can anyone explain why strings are converted to uppercase when the hashcode is calculated?
Can anyone explain why strings are converted to uppercase when the hashcode is calculated?
function TStringHelper.GetHashCode: Integer;
var
LResult: UInt32;
I: Integer;
Temp: string;
begin
Temp := Self.ToUpper; // ?????
LResult := 0;
for I := 0 to Temp.Length - 1 do
begin
LResult := (LResult shl 5) or (LResult shr 27); //ROL Result, 5
LResult := LResult xor UInt32(Temp[I]);
end;
Result := LResult;
end;
function TStringHelper.GetHashCode: Integer;
var
LResult: UInt32;
I: Integer;
Temp: string;
begin
Temp := Self.ToUpper; // ?????
LResult := 0;
for I := 0 to Temp.Length - 1 do
begin
LResult := (LResult shl 5) or (LResult shr 27); //ROL Result, 5
LResult := LResult xor UInt32(Temp[I]);
end;
Result := LResult;
end;
Joseph Mitzen that's what I meant by "unsupervised". No way on earth I'd let code into a SysUtils helper for a primitive type without intense code review by multiple seniors. They let this stuff out unread by any experienced developer.
ReplyDeleteIs there a QP report for any of this?
ReplyDeleteI'd say this absolutely should be fixed - but one thing I've observed is social media posting about issues, without actually reporting it to us. I do want to encourage bugs are reported, because we do see and track those.
Whining without report is quite useless... Sometimes is hard to find is there duplicate or not...
ReplyDelete