mirror of
https://github.com/rejetto/hfs2.git
synced 2025-12-19 10:03:56 +01:00
optimization: avoid resetting the array length when unnecessary
This commit is contained in:
parent
863c667f1b
commit
6c5139d552
28
main.pas
28
main.pas
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
Copyright (C) 2002-2020 Massimo Melina (www.rejetto.com)
|
Copyright (C) 2002-2020 Massimo Melina (www.rejetto.com)
|
||||||
|
|
||||||
This file is part of HFS ~ HTTP File Server.
|
This file is part of HFS ~ HTTP File Server.
|
||||||
@ -1365,6 +1365,7 @@ begin result:=reMatch(txt, '^'+quoteRegExprMetaChars(quoteIfAnyChar(' ',name)),
|
|||||||
|
|
||||||
type
|
type
|
||||||
TfileListing = class
|
TfileListing = class
|
||||||
|
actualCount: integer;
|
||||||
public
|
public
|
||||||
dir: array of Tfile;
|
dir: array of Tfile;
|
||||||
ignoreConnFilter: boolean;
|
ignoreConnFilter: boolean;
|
||||||
@ -1517,16 +1518,13 @@ end; // loadIon
|
|||||||
function TfileListing.fromFolder(folder:Tfile; cd:TconnData;
|
function TfileListing.fromFolder(folder:Tfile; cd:TconnData;
|
||||||
recursive:boolean=FALSE; limit:integer=-1; toSkip:integer=-1; doClear:boolean=TRUE):integer;
|
recursive:boolean=FALSE; limit:integer=-1; toSkip:integer=-1; doClear:boolean=TRUE):integer;
|
||||||
var
|
var
|
||||||
actualCount: integer;
|
|
||||||
seeProtected, noEmptyFolders, forArchive: boolean;
|
seeProtected, noEmptyFolders, forArchive: boolean;
|
||||||
filesFilter, foldersFilter, urlFilesFilter, urlFoldersFilter: string;
|
filesFilter, foldersFilter, urlFilesFilter, urlFoldersFilter: string;
|
||||||
|
|
||||||
procedure recurOn(f:Tfile);
|
procedure recurOn(f:Tfile);
|
||||||
begin
|
begin
|
||||||
if not f.isFolder() then exit;
|
if not f.isFolder() then exit;
|
||||||
setLength(dir, actualCount);
|
|
||||||
toSkip:=fromFolder(f, cd, TRUE, limit, toSkip, FALSE);
|
toSkip:=fromFolder(f, cd, TRUE, limit, toSkip, FALSE);
|
||||||
actualCount:=length(dir);
|
|
||||||
end; // recurOn
|
end; // recurOn
|
||||||
|
|
||||||
procedure addToListing(f:Tfile);
|
procedure addToListing(f:Tfile);
|
||||||
@ -1540,7 +1538,11 @@ var
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if actualCount >= length(dir) then
|
if actualCount >= length(dir) then
|
||||||
setLength(dir, actualCount+100);
|
begin
|
||||||
|
setLength(dir, actualCount+1000);
|
||||||
|
if actualCount > 0 then
|
||||||
|
mainfrm.setStatusBarText(format('Listing files: %s',[dotted(actualCount)]));
|
||||||
|
end;
|
||||||
dir[actualCount]:=f;
|
dir[actualCount]:=f;
|
||||||
inc(actualCount);
|
inc(actualCount);
|
||||||
end;
|
end;
|
||||||
@ -1719,8 +1721,7 @@ this would let us have "=" inside the names, but names cannot be assigned
|
|||||||
sr: TSearchRec;
|
sr: TSearchRec;
|
||||||
n: Ttreenode;
|
n: Ttreenode;
|
||||||
begin
|
begin
|
||||||
{ this folder has been dinamically generated, thus the node is not actually
|
// this folder has been dinamically generated, thus the node is not actually its own... skip
|
||||||
{ its own... skip }
|
|
||||||
if folder.isTemp() then exit;
|
if folder.isTemp() then exit;
|
||||||
|
|
||||||
// include (valid) items from the VFS branch
|
// include (valid) items from the VFS branch
|
||||||
@ -1785,7 +1786,8 @@ this would let us have "=" inside the names, but names cannot be assigned
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
result:=toSkip;
|
result:=toSkip;
|
||||||
if doClear then dir:=NIL;
|
if doClear then
|
||||||
|
actualCount:=0;
|
||||||
|
|
||||||
if not folder.isFolder()
|
if not folder.isFolder()
|
||||||
or not folder.accessFor(cd)
|
or not folder.accessFor(cd)
|
||||||
@ -1803,7 +1805,6 @@ if assigned(cd) then
|
|||||||
toSkip:=max(0, pred(strToIntDef(par('page'), 1))*limit);
|
toSkip:=max(0, pred(strToIntDef(par('page'), 1))*limit);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
actualCount:=length(dir);
|
|
||||||
folder.getFiltersRecursively(filesFilter, foldersFilter);
|
folder.getFiltersRecursively(filesFilter, foldersFilter);
|
||||||
if assigned(cd) and not ignoreConnFilter then
|
if assigned(cd) and not ignoreConnFilter then
|
||||||
begin
|
begin
|
||||||
@ -1827,7 +1828,10 @@ try
|
|||||||
if folder.isRealFolder() and not (FA_HIDDENTREE in folder.flags) and allowedTo(folder) then
|
if folder.isRealFolder() and not (FA_HIDDENTREE in folder.flags) and allowedTo(folder) then
|
||||||
includeFilesFromDisk();
|
includeFilesFromDisk();
|
||||||
includeItemsFromVFS();
|
includeItemsFromVFS();
|
||||||
finally setLength(dir, actualCount) end;
|
finally
|
||||||
|
if doClear then
|
||||||
|
setLength(dir, actualCount)
|
||||||
|
end;
|
||||||
result:=toSkip;
|
result:=toSkip;
|
||||||
end; // fromFolder
|
end; // fromFolder
|
||||||
|
|
||||||
@ -5102,7 +5106,7 @@ var
|
|||||||
|
|
||||||
antiDos:=TantiDos.create;
|
antiDos:=TantiDos.create;
|
||||||
try
|
try
|
||||||
tar:=TtarStream.create(); // this is freed by ThttpSrv
|
tar:=TtarStream.create();
|
||||||
try
|
try
|
||||||
tar.fileNamesOEM:=oemTarChk.checked;
|
tar.fileNamesOEM:=oemTarChk.checked;
|
||||||
addSelection();
|
addSelection();
|
||||||
@ -5123,7 +5127,7 @@ var
|
|||||||
conn.reply.mode:=HRM_REPLY;
|
conn.reply.mode:=HRM_REPLY;
|
||||||
conn.reply.contentType:=DEFAULT_MIME;
|
conn.reply.contentType:=DEFAULT_MIME;
|
||||||
conn.reply.bodyMode:=RBM_STREAM;
|
conn.reply.bodyMode:=RBM_STREAM;
|
||||||
conn.reply.bodyStream:=tar;
|
conn.reply.bodyStream:=tar; // it will be freed by ThttpSrv
|
||||||
|
|
||||||
if f.name = '' then exit; // can this really happen?
|
if f.name = '' then exit; // can this really happen?
|
||||||
data.lastFN:=if_(f.name='/', 'home', f.name)
|
data.lastFN:=if_(f.name='/', 'home', f.name)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user