mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
UPD: Don't need to initialize to zero class objects member variables because they are guaranteed to be zeroed in InitInstance (including static arrays and ref. counted strings).
UPD: Don't need to check if a pointer is assigned before calling Free, because Free already checks for nil pointer.
This commit is contained in:
parent
ee1e3f7e42
commit
e12e1df878
12 changed files with 33 additions and 134 deletions
|
|
@ -2271,18 +2271,11 @@ procedure TColumnsFileView.CreateDefault(AOwner: TWinControl);
|
|||
begin
|
||||
DCDebug('TColumnsFileView.Create components');
|
||||
|
||||
dgPanel := nil;
|
||||
|
||||
BorderStyle := bsNone; // Before Create or the window handle may be recreated
|
||||
inherited CreateDefault(AOwner);
|
||||
Align := alClient;
|
||||
|
||||
ActiveColm := '';
|
||||
ActiveColmSlave := nil;
|
||||
isSlave := False;
|
||||
FColumnsSorting := nil;
|
||||
FLastSelectionStartRow := -1;
|
||||
FUpdatingGrid := False;
|
||||
FFileNameColumn := -1;
|
||||
FExtensionColumn := -1;
|
||||
|
||||
|
|
@ -2388,8 +2381,9 @@ begin
|
|||
if Assigned(HotMan) then
|
||||
HotMan.UnRegister(dgPanel);
|
||||
|
||||
FreeThenNil(FColumnsSorting);
|
||||
inherited Destroy;
|
||||
|
||||
FColumnsSorting.Free;
|
||||
end;
|
||||
|
||||
function TColumnsFileView.Clone(NewParent: TWinControl): TColumnsFileView;
|
||||
|
|
@ -2564,8 +2558,7 @@ begin
|
|||
end;
|
||||
|
||||
finally
|
||||
if Assigned(AFileList) then
|
||||
FreeAndNil(AFileList);
|
||||
FreeAndNil(AFileList);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
|
@ -2735,8 +2728,7 @@ begin
|
|||
CalculateSpace(AFileList);
|
||||
|
||||
finally
|
||||
if Assigned(AFileList) then
|
||||
FreeAndNil(AFileList);
|
||||
FreeAndNil(AFileList);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -2757,8 +2749,7 @@ begin
|
|||
CalculateSpace(AFileList);
|
||||
|
||||
finally
|
||||
if Assigned(AFileList) then
|
||||
FreeAndNil(AFileList);
|
||||
FreeAndNil(AFileList);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -2833,8 +2824,7 @@ begin
|
|||
frmMain.DoDragDropOperation(Operation, DropParams);
|
||||
|
||||
finally
|
||||
if Assigned(DropParams) then
|
||||
FreeAndNil(DropParams);
|
||||
FreeAndNil(DropParams);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -3166,10 +3156,8 @@ end;
|
|||
|
||||
procedure TDrawGridEx.FinalizeWnd;
|
||||
begin
|
||||
if Assigned(DragDropSource) then
|
||||
FreeAndNil(DragDropSource);
|
||||
if Assigned(DragDropTarget) then
|
||||
FreeAndNil(DragDropTarget);
|
||||
FreeAndNil(DragDropSource);
|
||||
FreeAndNil(DragDropTarget);
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ implementation
|
|||
|
||||
constructor TDisplayFile.Create(ReferenceFile: TFile);
|
||||
begin
|
||||
FSelected := False;
|
||||
FIconID := -1;
|
||||
FIconOverlayID := -1;
|
||||
FFSFile := ReferenceFile;
|
||||
|
|
|
|||
|
|
@ -279,10 +279,6 @@ var
|
|||
begin
|
||||
inherited Create;
|
||||
|
||||
FSupportedProperties := [];
|
||||
for PropertyType := Low(TFilePropertyType) to High(TFilePropertyType) do
|
||||
FProperties[PropertyType] := nil;
|
||||
|
||||
// Name property always present.
|
||||
NameProperty := TFileNameProperty.Create;
|
||||
|
||||
|
|
@ -853,8 +849,7 @@ var
|
|||
begin
|
||||
inherited Destroy;
|
||||
|
||||
if Assigned(FFile) then
|
||||
FreeAndNil(FFile);
|
||||
FreeAndNil(FFile);
|
||||
|
||||
if Assigned(FSubNodes) then
|
||||
begin
|
||||
|
|
@ -863,8 +858,7 @@ begin
|
|||
FreeAndNil(FSubNodes);
|
||||
end;
|
||||
|
||||
if Assigned(FData) then
|
||||
FreeAndNil(FData);
|
||||
FreeAndNil(FData);
|
||||
end;
|
||||
|
||||
function TFileTreeNode.AddSubNode(aFile: TFile): Integer;
|
||||
|
|
|
|||
|
|
@ -365,8 +365,6 @@ begin
|
|||
inherited Create;
|
||||
|
||||
FReloadEventListeners := TMethodList.Create;
|
||||
for OperationType := Low(OperationType) to High(OperationType) do
|
||||
FOperationsClasses[OperationType] := nil;
|
||||
|
||||
FileSourceManager.Add(Self); // Increases RefCount
|
||||
|
||||
|
|
@ -413,7 +411,7 @@ begin
|
|||
else
|
||||
DCDebug('Error: Cannot remove file source - manager already destroyed!');
|
||||
|
||||
FreeThenNil(FReloadEventListeners);
|
||||
FreeAndNil(FReloadEventListeners);
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
|
@ -763,7 +761,6 @@ end;
|
|||
|
||||
constructor TFileSourceConnection.Create;
|
||||
begin
|
||||
FAssignedOperation := nil;
|
||||
FOperationLock := TCriticalSection.Create;
|
||||
inherited Create;
|
||||
DCDebug('Creating connection ', ClassName);
|
||||
|
|
@ -778,8 +775,7 @@ begin
|
|||
|
||||
DCDebug('Destroying connection ', ClassName);
|
||||
|
||||
if Assigned(FOperationLock) then
|
||||
FreeAndNil(FOperationLock);
|
||||
FreeAndNil(FOperationLock);
|
||||
end;
|
||||
|
||||
function TFileSourceConnection.GetAssignedOperation: TFileSourceOperation;
|
||||
|
|
@ -872,10 +868,9 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
if Assigned(FFileSources) then
|
||||
FreeAndNil(FFileSources);
|
||||
FreeAndNil(FFileSources);
|
||||
|
||||
inherited;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TFileSourceManager.Add(aFileSource: IFileSource);
|
||||
|
|
|
|||
|
|
@ -425,19 +425,12 @@ begin
|
|||
FState := fsosNotStarted;
|
||||
FDesiredState := fsosRunning; // set for auto-start unless prevented by PreventStart
|
||||
FOperationResult := fsorFinished;
|
||||
FProgress := 0;
|
||||
FPauseEvent := RTLEventCreate;
|
||||
FConnectionAvailableEvent := RTLEventCreate;
|
||||
FStateLock := TCriticalSection.Create;
|
||||
FEventsLock := TCriticalSection.Create;
|
||||
FThread := nil;
|
||||
FConnection := nil;
|
||||
FOperationInitialized := False;
|
||||
FParentOperation := nil;
|
||||
|
||||
{$IFNDEF fsoSynchronizeEvents}
|
||||
FScheduledEventsListenersCalls := 0;
|
||||
|
||||
FNoEventsListenersCallsScheduledEvent := RTLEventCreate;
|
||||
// Set at start because we don't have any calls scheduled at this time.
|
||||
RTLeventSetEvent(FNoEventsListenersCallsScheduledEvent);
|
||||
|
|
@ -450,8 +443,6 @@ begin
|
|||
|
||||
FStateChangedEventListeners := TFPList.Create;
|
||||
|
||||
FStartTime := 0;
|
||||
|
||||
FFileSource := aFileSource;
|
||||
|
||||
FNeedsConnection := (fspUsesConnections in (FileSource as IFileSource).Properties);
|
||||
|
|
|
|||
|
|
@ -95,9 +95,6 @@ constructor TFileSystemCopyOperation.Create(aSourceFileSource: IFileSource;
|
|||
var theSourceFiles: TFiles;
|
||||
aTargetPath: String);
|
||||
begin
|
||||
FSourceFilesTree := nil;
|
||||
FOperationHelper := nil;
|
||||
|
||||
// Here we can read global settings if there are any.
|
||||
FDropReadOnlyAttribute := False;
|
||||
FSymLinkOption := gOperationOptionSymLinks;
|
||||
|
|
@ -114,12 +111,8 @@ end;
|
|||
destructor TFileSystemCopyOperation.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
|
||||
if Assigned(FSourceFilesTree) then
|
||||
FreeAndNil(FSourceFilesTree);
|
||||
|
||||
if Assigned(FOperationHelper) then
|
||||
FreeAndNil(FOperationHelper);
|
||||
FreeAndNil(FSourceFilesTree);
|
||||
FreeAndNil(FOperationHelper);
|
||||
end;
|
||||
|
||||
procedure TFileSystemCopyOperation.Initialize;
|
||||
|
|
@ -176,8 +169,7 @@ end;
|
|||
|
||||
procedure TFileSystemCopyOperation.Finalize;
|
||||
begin
|
||||
if Assigned(FOperationHelper) then
|
||||
FreeAndNil(FOperationHelper);
|
||||
FreeAndNil(FOperationHelper);
|
||||
end;
|
||||
|
||||
class function TFileSystemCopyOperation.GetOptionsUIClass: TFileSourceOperationOptionsUIClass;
|
||||
|
|
|
|||
|
|
@ -69,12 +69,9 @@ begin
|
|||
FRecycle := False;
|
||||
FDeleteReadOnly := fsoogNone;
|
||||
FDeleteDirectly:= fsoogNone;
|
||||
FFullFilesTreeToDelete := nil;
|
||||
|
||||
if gProcessComments then
|
||||
FDescription := TDescription.Create(True)
|
||||
else
|
||||
FDescription := nil;
|
||||
FDescription := TDescription.Create(True);
|
||||
|
||||
inherited Create(aTargetFileSource, theFilesToDelete);
|
||||
end;
|
||||
|
|
@ -91,8 +88,7 @@ begin
|
|||
|
||||
if not FRecycle then
|
||||
begin
|
||||
if Assigned(FFullFilesTreeToDelete) then
|
||||
FreeAndNil(FFullFilesTreeToDelete);
|
||||
FreeAndNil(FFullFilesTreeToDelete);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
|
|||
|
|
@ -147,9 +147,6 @@ begin
|
|||
with AFile do
|
||||
begin
|
||||
OwnerProperty := TFileOwnerProperty.Create;
|
||||
OwnerProperty.Owner := 0;
|
||||
OwnerProperty.Group := 0;
|
||||
|
||||
if GetFileOwner(FullPath, sUser, sGroup) then
|
||||
begin
|
||||
OwnerProperty.OwnerStr := sUser;
|
||||
|
|
@ -285,9 +282,8 @@ end;
|
|||
|
||||
destructor TFileSystemFileSource.Destroy;
|
||||
begin
|
||||
if Assigned(FDescr) then
|
||||
FreeAndNil(FDescr);
|
||||
inherited Destroy;
|
||||
FDescr.Free;
|
||||
end;
|
||||
|
||||
class function TFileSystemFileSource.CreateFile(const APath: String): TFile;
|
||||
|
|
|
|||
|
|
@ -59,9 +59,6 @@ constructor TFileSystemMoveOperation.Create(aFileSource: IFileSource;
|
|||
var theSourceFiles: TFiles;
|
||||
aTargetPath: String);
|
||||
begin
|
||||
FSourceFilesTree := nil;
|
||||
FOperationHelper := nil;
|
||||
|
||||
// Here we can read global settings if there are any.
|
||||
FFileExistsOption := gOperationOptionFileExists;
|
||||
FDirExistsOption := gOperationOptionDirectoryExists;
|
||||
|
|
@ -75,12 +72,8 @@ end;
|
|||
destructor TFileSystemMoveOperation.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
|
||||
if Assigned(FSourceFilesTree) then
|
||||
FreeAndNil(FSourceFilesTree);
|
||||
|
||||
if Assigned(FOperationHelper) then
|
||||
FreeAndNil(FOperationHelper);
|
||||
FreeAndNil(FSourceFilesTree);
|
||||
FreeAndNil(FOperationHelper);
|
||||
end;
|
||||
|
||||
procedure TFileSystemMoveOperation.Initialize;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ type
|
|||
public
|
||||
// True if any of the subnodes (recursively) are links.
|
||||
SubnodesHaveLinks: Boolean;
|
||||
|
||||
constructor Create;
|
||||
end;
|
||||
|
||||
TUpdateStatisticsFunction = procedure(var NewStatistics: TFileSourceCopyOperationStatistics) of object;
|
||||
|
|
@ -313,21 +311,12 @@ end;
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
constructor TFileTreeNodeData.Create;
|
||||
begin
|
||||
SubnodesHaveLinks := False;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
constructor TFileSystemTreeBuilder.Create(AskQuestionFunction: TAskQuestionFunction;
|
||||
CheckOperationStateFunction: TCheckOperationStateFunction);
|
||||
begin
|
||||
AskQuestion := AskQuestionFunction;
|
||||
CheckOperationState := CheckOperationStateFunction;
|
||||
|
||||
FFilesTree := nil;
|
||||
FExcludeRootDir := False;
|
||||
FRecursive := True;
|
||||
FSymlinkOption := fsooslNone;
|
||||
end;
|
||||
|
|
@ -335,17 +324,14 @@ end;
|
|||
destructor TFileSystemTreeBuilder.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
|
||||
if Assigned(FFilesTree) then
|
||||
FreeAndNil(FFilesTree);
|
||||
FFilesTree.Free;
|
||||
end;
|
||||
|
||||
procedure TFileSystemTreeBuilder.BuildFromFiles(Files: TFiles);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if Assigned(FFilesTree) then
|
||||
FreeAndNil(FFilesTree);
|
||||
FreeAndNil(FFilesTree);
|
||||
|
||||
FFilesTree := TFileTreeNode.Create;
|
||||
FFilesTree.Data := TFileTreeNodeData.Create;
|
||||
|
|
@ -841,8 +827,7 @@ begin
|
|||
end;
|
||||
|
||||
finally
|
||||
if Assigned(SourceFileStream) then
|
||||
FreeAndNil(SourceFileStream);
|
||||
FreeAndNil(SourceFileStream);
|
||||
if Assigned(TargetFileStream) then
|
||||
begin
|
||||
FreeAndNil(TargetFileStream);
|
||||
|
|
|
|||
|
|
@ -445,36 +445,16 @@ end;
|
|||
|
||||
procedure TFileView.CreateDefault(AOwner: TWinControl);
|
||||
begin
|
||||
FOnBeforeChangePath := nil;
|
||||
FOnAfterChangePath := nil;
|
||||
FOnChangeActiveFile := nil;
|
||||
FOnActivate := nil;
|
||||
FOnReload := nil;
|
||||
FSortings := nil;
|
||||
FFilePropertiesNeeded := [];
|
||||
FMethods := TFormCommands.Create(Self);
|
||||
FHistory := TFileViewHistory.Create;
|
||||
FSavedSelection:= TStringListEx.Create;
|
||||
FActive := False;
|
||||
FLastActiveFile := '';
|
||||
FRequestedActiveFile := '';
|
||||
FLastMark := '*';
|
||||
FFileFilter := '';
|
||||
FFilterOptions := gQuickSearchOptions;
|
||||
FFiles := nil;
|
||||
FHashedFiles := nil;
|
||||
FHashedNames := TStringHashList.Create(True);
|
||||
FWorkersThread := nil;
|
||||
FReloading := False;
|
||||
FReloadNeeded := False;
|
||||
FFileViewWorkers := TFileViewWorkers.Create(False);
|
||||
FWatchPath := EmptyStr;
|
||||
FReloadTimer := TTimer.Create(Self);
|
||||
FReloadTimer.Enabled := False;
|
||||
FReloadTimer.OnTimer := @ReloadTimerEvent;
|
||||
FLoadFilesStartTime := 0;
|
||||
FLoadFilesFinishTime := 0;
|
||||
FLoadFilesNoDelayCount := 0;
|
||||
|
||||
inherited Create(AOwner);
|
||||
Parent := AOwner;
|
||||
|
|
@ -522,11 +502,9 @@ begin
|
|||
|
||||
RemoveAllFileSources;
|
||||
|
||||
if Assigned(FFiles) then
|
||||
FreeAndNil(FFiles);
|
||||
FreeAndNil(FFiles);
|
||||
FreeAndNil(FAllDisplayFiles);
|
||||
if Assigned(FHashedFiles) then
|
||||
FreeAndNil(FHashedFiles);
|
||||
FreeAndNil(FHashedFiles);
|
||||
FreeAndNil(FHashedNames);
|
||||
|
||||
inherited Destroy;
|
||||
|
|
@ -955,8 +933,7 @@ var
|
|||
i: Integer;
|
||||
begin
|
||||
// Cannot use FHashedFiles.Clear because it also destroys the buckets.
|
||||
if Assigned(FHashedFiles) then
|
||||
FHashedFiles.Free;
|
||||
FHashedFiles.Free;
|
||||
// TBucketList seems to do fairly well without needing a proper hash table.
|
||||
FHashedFiles := TBucketList.Create(bl256);
|
||||
FHashedNames.Clear;
|
||||
|
|
@ -1788,8 +1765,8 @@ end;
|
|||
|
||||
destructor TDropParams.Destroy;
|
||||
begin
|
||||
if Assigned(Files) then
|
||||
FreeAndNil(Files);
|
||||
inherited Destroy;
|
||||
FreeAndNil(Files);
|
||||
end;
|
||||
|
||||
function TDropParams.GetDragDropType: TDragDropType;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type
|
|||
TFileViewWorker = class
|
||||
strict private
|
||||
FAborted: Boolean;
|
||||
{en After FCanBeDestroyed is set to True the worker may be destroyed.}
|
||||
FCanBeDestroyed: Boolean;
|
||||
FWorking: Boolean;
|
||||
FOnStarting: TStartingWorkMethod;
|
||||
|
|
@ -260,17 +261,11 @@ end;
|
|||
|
||||
constructor TFileViewWorker.Create(AThread: TThread);
|
||||
begin
|
||||
FAborted := False;
|
||||
// After FCanBeDestroyed is set to True the worker may be destroyed.
|
||||
FCanBeDestroyed := False;
|
||||
|
||||
// Set Working=True on creation because these workers are usually scheduled
|
||||
// to run by a non-main thread, so it might take a while for Execute to be called.
|
||||
FWorking := True;
|
||||
FWorkType := fvwtNone;
|
||||
|
||||
FOnStarting := nil;
|
||||
FOnFinished := nil;
|
||||
FThread := AThread;
|
||||
end;
|
||||
|
||||
|
|
@ -872,12 +867,10 @@ begin
|
|||
end;
|
||||
|
||||
finally
|
||||
if Assigned(TargetFiles) then
|
||||
FreeAndNil(TargetFiles);
|
||||
FreeAndNil(TargetFiles);
|
||||
FOperationLock.Acquire;
|
||||
try
|
||||
if Assigned(FOperation) then
|
||||
FreeAndNil(FOperation);
|
||||
FreeAndNil(FOperation);
|
||||
finally
|
||||
FOperationLock.Release;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue