IdeDebugger: Optimize ValueFormatter search (cache uppercased string)

This commit is contained in:
Martin 2024-08-25 13:24:06 +02:00
parent 4e9fcdc1eb
commit d55646e450

View File

@ -55,6 +55,9 @@ type
function DoFormatValue(AWatchValue: IWatchResultDataIntf; ADisplayFormat: TWatchDisplayFormat; function DoFormatValue(AWatchValue: IWatchResultDataIntf; ADisplayFormat: TWatchDisplayFormat;
AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String
): Boolean; ): Boolean;
function MatchesAll(AWatchValue: IWatchResultDataIntf; ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer;
const AWatchedVarUpper, AWatchedExprUpper: String;
var AWatchedTypeUpper: String; var AWatchedTypeUpperDone: Boolean): Boolean;
public public
constructor Create; constructor Create;
constructor Create(AFormatter: TLazDbgIdeValueFormatterRegistryEntryClass); constructor Create(AFormatter: TLazDbgIdeValueFormatterRegistryEntryClass);
@ -65,8 +68,6 @@ type
procedure LoadDataFromXMLConfig(const AConfig: TRttiXMLConfig; const APath: string); procedure LoadDataFromXMLConfig(const AConfig: TRttiXMLConfig; const APath: string);
procedure SaveDataToXMLConfig(const AConfig: TRttiXMLConfig; const APath: string); procedure SaveDataToXMLConfig(const AConfig: TRttiXMLConfig; const APath: string);
function MatchesAll(AWatchValue: IWatchResultDataIntf; ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer;
const AWatchedVarUpper, AWatchedExprUpper: String): Boolean;
function FormatValue(AWatchValue: IWatchResultDataIntf; function FormatValue(AWatchValue: IWatchResultDataIntf;
ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer; ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer;
AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String; AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String;
@ -271,7 +272,8 @@ end;
function TIdeDbgValueFormatterSelector.MatchesAll(AWatchValue: IWatchResultDataIntf; function TIdeDbgValueFormatterSelector.MatchesAll(AWatchValue: IWatchResultDataIntf;
ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer; const AWatchedVarUpper, ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer; const AWatchedVarUpper,
AWatchedExprUpper: String): Boolean; AWatchedExprUpper: String; var AWatchedTypeUpper: String; var AWatchedTypeUpperDone: Boolean
): Boolean;
var var
j: Integer; j: Integer;
a: IWatchResultDataIntf; a: IWatchResultDataIntf;
@ -287,7 +289,11 @@ begin
then then
exit; exit;
if not IsMatchingTypeName(AnsiUpperCase(AWatchValue.TypeName)) then begin if not AWatchedTypeUpperDone then begin
AWatchedTypeUpper := AnsiUpperCase(AWatchValue.TypeName);
AWatchedTypeUpperDone := True;
end;
if not IsMatchingTypeName(AWatchedTypeUpper) then begin
if not MatchInherited then if not MatchInherited then
exit; exit;
j := AWatchValue.AnchestorCount - 1; j := AWatchValue.AnchestorCount - 1;
@ -311,8 +317,13 @@ function TIdeDbgValueFormatterSelector.FormatValue(AWatchValue: IWatchResultData
ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer; ADisplayFormat: TWatchDisplayFormat; ANestLevel: integer;
AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String; AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String;
const AWatchedVarUpper, AWatchedExprUpper: String): Boolean; const AWatchedVarUpper, AWatchedExprUpper: String): Boolean;
var
AWatchedTypeUpper: String;
AWatchedTypeUpperDone: Boolean;
begin begin
Result := MatchesAll(AWatchValue, ADisplayFormat, ANestLevel, AWatchedVarUpper, AWatchedExprUpper); AWatchedTypeUpperDone := False;
Result := MatchesAll(AWatchValue, ADisplayFormat, ANestLevel,
AWatchedVarUpper, AWatchedExprUpper, AWatchedTypeUpper, AWatchedTypeUpperDone);
if Result then if Result then
Result := DoFormatValue(AWatchValue, ADisplayFormat, AWatchResultPrinter, APrintedValue); Result := DoFormatValue(AWatchValue, ADisplayFormat, AWatchResultPrinter, APrintedValue);
end; end;
@ -477,10 +488,15 @@ function TIdeDbgValueFormatterSelectorList.FormatValue(AWatchValue: IWatchResult
var var
i: Integer; i: Integer;
f: TIdeDbgValueFormatterSelector; f: TIdeDbgValueFormatterSelector;
AWatchedTypeUpper: String;
AWatchedTypeUpperDone: Boolean;
begin begin
AWatchedTypeUpperDone := False;
for i := 0 to Count - 1 do begin for i := 0 to Count - 1 do begin
f := Items[i]; f := Items[i];
if not f.MatchesAll(AWatchValue, ADisplayFormat, ANestLevel, AWatchedVarUpper, AWatchedExprUpper) then if not f.MatchesAll(AWatchValue, ADisplayFormat, ANestLevel,
AWatchedVarUpper, AWatchedExprUpper, AWatchedTypeUpper, AWatchedTypeUpperDone)
then
continue; continue;
Result := f.DoFormatValue(AWatchValue, ADisplayFormat, AWatchResultPrinter, APrintedValue); Result := f.DoFormatValue(AWatchValue, ADisplayFormat, AWatchResultPrinter, APrintedValue);