Browse Source

Cached the file-related properties of TranslationUnit to avoid the performance cost.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/510/head
Dimitar Dobrev 10 years ago
parent
commit
e014ffbe15
  1. 20
      src/AST/TranslationUnit.cs

20
src/AST/TranslationUnit.cs

@ -31,28 +31,39 @@ namespace CppSharp.AST
/// Contains the path to the file. /// Contains the path to the file.
public string FilePath; public string FilePath;
private string fileName;
private string fileNameWithoutExtension;
/// Contains the name of the file. /// Contains the name of the file.
public string FileName public string FileName
{ {
get { return Path.GetFileName(FilePath); } get { return fileName ?? (fileName = Path.GetFileName(FilePath)); }
} }
/// Contains the name of the module. /// Contains the name of the module.
public string FileNameWithoutExtension public string FileNameWithoutExtension
{ {
get { return Path.GetFileNameWithoutExtension(FileName); } get
{
return fileNameWithoutExtension ??
(fileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileName));
}
} }
/// Contains the include path. /// Contains the include path.
public string IncludePath; public string IncludePath;
private string fileRelativeDirectory;
private string fileRelativePath;
public string FileRelativeDirectory public string FileRelativeDirectory
{ {
get get
{ {
if (fileRelativeDirectory != null) return fileRelativeDirectory;
var path = IncludePath.Replace('\\', '/'); var path = IncludePath.Replace('\\', '/');
var index = path.LastIndexOf('/'); var index = path.LastIndexOf('/');
return path.Substring(0, index); return fileRelativeDirectory = path.Substring(0, index);
} }
} }
@ -60,7 +71,8 @@ namespace CppSharp.AST
{ {
get get
{ {
return Path.Combine(FileRelativeDirectory, FileName); return fileRelativePath ??
(fileRelativePath = Path.Combine(FileRelativeDirectory, FileName));
} }
} }
} }

Loading…
Cancel
Save