avoid using stat calls if possible (reusing cached data if needed)
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3308
This commit is contained in:
parent
9725773407
commit
ad13c63c32
2 changed files with 25 additions and 17 deletions
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: dos_system.h,v 1.44 2009-02-20 14:19:43 c2woody Exp $ */
|
||||
/* $Id: dos_system.h,v 1.45 2009-02-24 17:56:55 c2woody Exp $ */
|
||||
|
||||
#ifndef DOSBOX_DOS_SYSTEM_H
|
||||
#define DOSBOX_DOS_SYSTEM_H
|
||||
|
@ -105,12 +105,12 @@ public:
|
|||
open=true;
|
||||
return *this;
|
||||
}
|
||||
DOS_Device():DOS_File(),devnum(0){};
|
||||
DOS_Device():DOS_File(),devnum(0){};
|
||||
virtual bool Read(Bit8u * data,Bit16u * size);
|
||||
virtual bool Write(Bit8u * data,Bit16u * size);
|
||||
virtual bool Seek(Bit32u * pos,Bit32u type);
|
||||
virtual bool Close();
|
||||
virtual Bit16u GetInformation(void);
|
||||
virtual Bit16u GetInformation(void);
|
||||
virtual bool ReadFromControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
|
||||
virtual bool WriteToControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
|
||||
void SetDeviceNumber(Bitu num) { devnum=num;}
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
Bitu devnum;
|
||||
};
|
||||
|
||||
/* The following variable can be lowered to free up some memory.
|
||||
/* The following variable can be lowered to free up some memory.
|
||||
* The negative side effect: The stored searches will be turned over faster.
|
||||
* Should not have impact on systems with few directory entries. */
|
||||
#define MAX_OPENDIRS 2048
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
void ExpandName (char* path);
|
||||
char* GetExpandName (const char* path);
|
||||
bool GetShortName (const char* fullname, char* shortname);
|
||||
|
||||
|
||||
bool FindFirst (char* path, Bitu& id);
|
||||
bool FindNext (Bitu id, char* &result);
|
||||
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
char* GetLabel (void) { return label; };
|
||||
|
||||
class CFileInfo {
|
||||
public:
|
||||
public:
|
||||
CFileInfo(void) {
|
||||
orgname[0] = shortname[0] = 0;
|
||||
nextEntry = shortNr = 0;
|
||||
|
@ -186,7 +186,7 @@ private:
|
|||
CFileInfo* FindDirInfo (const char* path, char* expandedPath);
|
||||
bool RemoveSpaces (char* str);
|
||||
bool OpenDir (CFileInfo* dir, const char* path, Bit16u& id);
|
||||
void CreateEntry (CFileInfo* dir, const char* name);
|
||||
void CreateEntry (CFileInfo* dir, const char* name, Bitu query_directory);
|
||||
Bit16u GetFreeID (CFileInfo* dir);
|
||||
void Clear (void);
|
||||
|
||||
|
@ -241,7 +241,7 @@ public:
|
|||
virtual char const * GetLabel(){return dirCache.GetLabel();};
|
||||
|
||||
DOS_Drive_Cache dirCache;
|
||||
|
||||
|
||||
// disk cycling functionality (request resources)
|
||||
virtual void Activate(void) {};
|
||||
};
|
||||
|
@ -251,8 +251,8 @@ enum { DOS_SEEK_SET=0,DOS_SEEK_CUR=1,DOS_SEEK_END=2};
|
|||
|
||||
|
||||
/*
|
||||
A multiplex handler should read the registers to check what function is being called
|
||||
If the handler returns false dos will stop checking other handlers
|
||||
A multiplex handler should read the registers to check what function is being called
|
||||
If the handler returns false dos will stop checking other handlers
|
||||
*/
|
||||
|
||||
typedef bool (MultiplexHandler)(void);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: drive_cache.cpp,v 1.55 2009-02-20 14:19:47 c2woody Exp $ */
|
||||
/* $Id: drive_cache.cpp,v 1.56 2009-02-24 17:56:55 c2woody Exp $ */
|
||||
|
||||
#include "drives.h"
|
||||
#include "dos_inc.h"
|
||||
|
@ -220,7 +220,7 @@ void DOS_Drive_Cache::AddEntry(const char* path, bool checkExists) {
|
|||
if (GetLongName(dir,file)>=0) return;
|
||||
}
|
||||
|
||||
CreateEntry(dir,file);
|
||||
CreateEntry(dir,file,0);
|
||||
|
||||
Bits index = GetLongName(dir,file);
|
||||
if (index>=0) {
|
||||
|
@ -627,7 +627,7 @@ bool DOS_Drive_Cache::OpenDir(CFileInfo* dir, const char* expand, Bit16u& id)
|
|||
return false;
|
||||
};
|
||||
|
||||
void DOS_Drive_Cache::CreateEntry(CFileInfo* dir, const char* name) {
|
||||
void DOS_Drive_Cache::CreateEntry(CFileInfo* dir, const char* name, Bitu is_directory) {
|
||||
struct stat status;
|
||||
CFileInfo* info = new CFileInfo;
|
||||
strcpy(info->orgname ,name);
|
||||
|
@ -636,8 +636,13 @@ void DOS_Drive_Cache::CreateEntry(CFileInfo* dir, const char* name) {
|
|||
char buffer[CROSS_LEN];
|
||||
strcpy(buffer,dirPath);
|
||||
strcat(buffer,info->orgname);
|
||||
if (stat(buffer,&status)==0) info->isDir = (S_ISDIR(status.st_mode)>0);
|
||||
else info->isDir = false;
|
||||
switch (is_directory) {
|
||||
case 0: info->isDir = false; break;
|
||||
case 1: info->isDir = true; break;
|
||||
case 2:
|
||||
if (stat(buffer,&status)==0) info->isDir = (S_ISDIR(status.st_mode)>0);
|
||||
else info->isDir = false;
|
||||
}
|
||||
// Check for long filenames...
|
||||
CreateShortName(dir, info);
|
||||
|
||||
|
@ -682,7 +687,9 @@ bool DOS_Drive_Cache::ReadDir(Bit16u id, char* &result)
|
|||
// Read complete directory
|
||||
struct dirent* tmpres;
|
||||
while ((tmpres = readdir(dirp))!=NULL) {
|
||||
CreateEntry(dirSearch[id],tmpres->d_name);
|
||||
// is_dir from readdir??
|
||||
CreateEntry(dirSearch[id],tmpres->d_name,2);
|
||||
// CreateEntry(dirSearch[id],tmpres->d_name,(tmpres->d_type==DT_DIR)?1:0);
|
||||
}
|
||||
// close dir
|
||||
closedir(dirp);
|
||||
|
@ -743,7 +750,8 @@ bool DOS_Drive_Cache::FindFirst(char* path, Bitu& id) {
|
|||
|
||||
// Copy entries to use with FindNext
|
||||
for (Bitu i=0; i<dirSearch[dirID]->fileList.size(); i++) {
|
||||
CreateEntry(dirFindFirst[dirFindFirstID],dirSearch[dirID]->fileList[i]->orgname);
|
||||
CreateEntry(dirFindFirst[dirFindFirstID],dirSearch[dirID]->fileList[i]->orgname,
|
||||
dirSearch[dirID]->fileList[i]->isDir?1:0);
|
||||
}
|
||||
// Now re-sort the fileList accordingly to output
|
||||
switch (sortDirType) {
|
||||
|
|
Loading…
Add table
Reference in a new issue