[cfe-commits] r64351 - in /cfe/trunk: include/clang/Basic/FileManager.h lib/Basic/FileManager.cpp
Ted Kremenek
kremenek at apple.com
Wed Feb 11 19:17:57 PST 2009
Author: kremenek
Date: Wed Feb 11 21:17:57 2009
New Revision: 64351
URL: http://llvm.org/viewvc/llvm-project?rev=64351&view=rev
Log:
FileManager:
- set the 'StatSysCallCache' object using a setter method instead of
FileManager's constructor. This allows the cache to be installed after the
FileManager object is created.
- Add 'file mode' to FileEntry (useful for stat caching)
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=64351&r1=64350&r2=64351&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Wed Feb 11 21:17:57 2009
@@ -15,6 +15,7 @@
#define LLVM_CLANG_FILEMANAGER_H
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/Bitcode/SerializationFwd.h"
#include "llvm/Support/Allocator.h"
#include <map>
@@ -47,11 +48,13 @@
unsigned UID; // A unique (small) ID for the file.
dev_t Device; // ID for the device containing the file.
ino_t Inode; // Inode number for the file.
+ mode_t FileMode; // The file mode as returned by 'stat'.
friend class FileManager;
public:
- FileEntry(dev_t device, ino_t inode) : Name(0), Device(device), Inode(inode){}
+ FileEntry(dev_t device, ino_t inode, mode_t m)
+ : Name(0), Device(device), Inode(inode), FileMode(m) {}
// Add a default constructor for use with llvm::StringMap
- FileEntry() : Name(0), Device(0), Inode(0) {}
+ FileEntry() : Name(0), Device(0), Inode(0), FileMode(0) {}
const char *getName() const { return Name; }
off_t getSize() const { return Size; }
@@ -59,6 +62,7 @@
ino_t getInode() const { return Inode; }
dev_t getDevice() const { return Device; }
time_t getModificationTime() const { return ModTime; }
+ mode_t getFileMode() const { return FileMode; }
/// getDir - Return the directory the file lives in.
///
@@ -108,15 +112,21 @@
unsigned NumDirCacheMisses, NumFileCacheMisses;
// Caching.
- StatSysCallCache *StatCache;
+ llvm::OwningPtr<StatSysCallCache> StatCache;
+
int stat_cached(const char* path, struct stat* buf) {
- return StatCache ? StatCache->stat(path, buf) : stat(path, buf);
+ return StatCache.get() ? StatCache->stat(path, buf) : stat(path, buf);
}
public:
- FileManager(StatSysCallCache *statCache = 0);
+ FileManager();
~FileManager();
+ /// setStatCache - Installs the provided StatSysCallCache object within
+ /// the FileManager. Ownership of this object is transferred to the
+ /// FileManager.
+ void setStatCache(StatSysCallCache *statCache) { StatCache.reset(statCache); }
+
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
///
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=64351&r1=64350&r2=64351&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Feb 11 21:17:57 2009
@@ -122,7 +122,8 @@
return
const_cast<FileEntry&>(
*UniqueFiles.insert(FileEntry(StatBuf.st_dev,
- StatBuf.st_ino)).first);
+ StatBuf.st_ino,
+ StatBuf.st_mode)).first);
}
size_t size() { return UniqueFiles.size(); }
@@ -134,11 +135,10 @@
// Common logic.
//===----------------------------------------------------------------------===//
-FileManager::FileManager(StatSysCallCache* statCache)
+FileManager::FileManager()
: UniqueDirs(*new UniqueDirContainer),
UniqueFiles(*new UniqueFileContainer),
- DirEntries(64), FileEntries(64), NextFileUID(0),
- StatCache(statCache) {
+ DirEntries(64), FileEntries(64), NextFileUID(0) {
NumDirLookups = NumFileLookups = 0;
NumDirCacheMisses = NumFileCacheMisses = 0;
}
@@ -146,10 +146,8 @@
FileManager::~FileManager() {
delete &UniqueDirs;
delete &UniqueFiles;
- delete StatCache;
}
-
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
///
More information about the cfe-commits
mailing list