[cfe-commits] r45184 - in /cfe/trunk: Basic/FileManager.cpp include/clang/Basic/FileManager.h

Chris Lattner clattner at apple.com
Tue Dec 18 20:51:39 PST 2007


On Dec 18, 2007, at 2:29 PM, Ted Kremenek wrote:

> Author: kremenek
> Date: Tue Dec 18 16:29:39 2007
> New Revision: 45184
>
> URL: http://llvm.org/viewvc/llvm-project?rev=45184&view=rev
> Log:
> Refactored inode and device number into FileEntry, and changed the
> ADT storing FileEntry's in FileManager from a map to a set.

Thanks Ted!  Please comment this liberally :)

-Chris

>
> Modified:
>    cfe/trunk/Basic/FileManager.cpp
>    cfe/trunk/include/clang/Basic/FileManager.h
>
> Modified: cfe/trunk/Basic/FileManager.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/FileManager.cpp?rev=45184&r1=45183&r2=45184&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/Basic/FileManager.cpp (original)
> +++ cfe/trunk/Basic/FileManager.cpp Tue Dec 18 16:29:39 2007
> @@ -142,14 +142,12 @@
>   }
>   //std::cerr << ": exists\n";
>
> -  // It exists.  See if we have already opened a directory with the  
> same inode.
> +  // It exists.  See if we have already opened a file with the same  
> inode.
>   // This occurs when one dir is symlinked to another, for example.
> -  std::pair<FileEntryMap::iterator,bool> X =
> -     
> UniqueFiles 
> .insert(FileEntryMap::value_type(std::make_pair(StatBuf.st_dev,
> -                                                                
> StatBuf.st_ino),
> -                                                FileEntry()));
> -
> -  FileEntry &UFE = X.first->second;
> +  FileEntry &UFE =
> +     
> const_cast<FileEntry&>(*UniqueFiles.insert(FileEntry(StatBuf.st_dev,
> +                                                          
> StatBuf.st_ino)).first);
> +
>
>   NamedFileEnt.setValue(&UFE);
>   if (UFE.getName())  // Already have an entry with this inode,  
> return it.
> @@ -163,7 +161,6 @@
>   UFE.ModTime = StatBuf.st_mtime;
>   UFE.Dir     = DirInfo;
>   UFE.UID     = NextFileUID++;
> -  UFE.InoDev  = &X.first->first;
>   return &UFE;
> }
>
>
> Modified: cfe/trunk/include/clang/Basic/FileManager.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=45184&r1=45183&r2=45184&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Basic/FileManager.h (original)
> +++ cfe/trunk/include/clang/Basic/FileManager.h Tue Dec 18 16:29:39  
> 2007
> @@ -17,6 +17,7 @@
> #include "llvm/ADT/StringMap.h"
> #include "llvm/Bitcode/SerializationFwd.h"
> #include <map>
> +#include <set>
> #include <string>
> // FIXME: Enhance libsystem to support inode and other fields in stat.
> #include <sys/types.h>
> @@ -42,21 +43,26 @@
>   time_t ModTime;             // Modification time of file.
>   const DirectoryEntry *Dir;  // Directory file lives in.
>   unsigned UID;               // A unique (small) ID for the file.
> -  const std::pair<dev_t, ino_t>* InoDev; // Pointer to inode/device  
> number pair.
> +  dev_t Device;               // ID for the device containing the  
> file.
> +  ino_t Inode;                // Inode number for the file.
>   friend class FileManager;
> public:
> -  FileEntry() : Name(0), InoDev(NULL) {}
> +  FileEntry(dev_t device, ino_t inode) : Name(0), Device(device),  
> Inode(inode){}
>
>   const char *getName() const { return Name; }
>   off_t getSize() const { return Size; }
>   unsigned getUID() const { return UID; }
> -  ino_t getInode() const { return InoDev->second; }
> -  dev_t getDev() const { return InoDev->first; }
> +  ino_t getInode() const { return Inode; }
> +  dev_t getDev() const { return Device; }
>   time_t getModificationTime() const { return ModTime; }
>
>   /// getDir - Return the directory the file lives in.
>   ///
>   const DirectoryEntry *getDir() const { return Dir; }
> +
> +  bool operator<(const FileEntry& RHS) const {
> +    return Device < RHS.Device || (Device == RHS.Device && Inode <  
> RHS.Inode);
> +  }
> };
>
>
> @@ -68,10 +74,8 @@
> class FileManager {
>   /// UniqueDirs/UniqueFiles - Cache from ID's to existing  
> directories/files.
>   ///
> -  std::map<std::pair<dev_t, ino_t>, DirectoryEntry> UniqueDirs;
> -
> -  typedef std::map<std::pair<dev_t, ino_t>, FileEntry> FileEntryMap;
> -  FileEntryMap UniqueFiles;
> +  std::map<std::pair<dev_t, ino_t>, DirectoryEntry> UniqueDirs;
> +  std::set<FileEntry> UniqueFiles;
>
>   /// DirEntries/FileEntries - This is a cache of directory/file  
> entries we have
>   /// looked up.  The actual Entry is owned by UniqueFiles/ 
> UniqueDirs above.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list