@@ -1042,6 +1042,16 @@ private Dictionary<string, FileMetadataByVersion>
1042
1042
metadataByCanonicalFilename =
1043
1043
new Dictionary < string , FileMetadataByVersion > ( ) ;
1044
1044
1045
+ /// <summary>
1046
+ /// Dictionary of FileMetadata indexed by filename in the project and the export path if
1047
+ /// it exists. This is the inverse mapping of metadataByCanonicalFilename.
1048
+ /// </summary>
1049
+ /// <remarks>
1050
+ /// This shouldn't not be modified directly, use Add() and Clear() instead.
1051
+ /// </remarks>
1052
+ private Dictionary < string , FileMetadata > metadataByFilename =
1053
+ new Dictionary < string , FileMetadata > ( ) ;
1054
+
1045
1055
/// <summary>
1046
1056
/// Get the FileMetadataByVersion for each filename bucket in this set.
1047
1057
/// </summary>
@@ -1050,6 +1060,13 @@ public Dictionary<string, FileMetadataByVersion>.ValueCollection
1050
1060
get { return metadataByCanonicalFilename . Values ; }
1051
1061
}
1052
1062
1063
+ /// <summary>
1064
+ /// Retrieves a map of in-project filename to file metadata.
1065
+ /// </summary>
1066
+ public Dictionary < string , FileMetadata > MetadataByFilename {
1067
+ get { return metadataByFilename ; }
1068
+ }
1069
+
1053
1070
/// <summary>
1054
1071
/// Construct an instance.
1055
1072
/// </summary>
@@ -1079,6 +1096,7 @@ public static FileMetadataSet FilterOutUnityPackageManagerFiles(
1079
1096
/// </summary>
1080
1097
public void Clear ( ) {
1081
1098
metadataByCanonicalFilename = new Dictionary < string , FileMetadataByVersion > ( ) ;
1099
+ metadataByFilename = new Dictionary < string , FileMetadata > ( ) ;
1082
1100
}
1083
1101
1084
1102
/// <summary>
@@ -1096,6 +1114,7 @@ public void Add(FileMetadata metadata) {
1096
1114
/// <param name="metadata">File metadata to add to the set.</param>
1097
1115
public void Add ( string filenameCanonical , FileMetadata metadata ) {
1098
1116
FindMetadataByVersion ( filenameCanonical , true ) . Add ( metadata ) ;
1117
+ UpdateMetadataByFilename ( metadata ) ;
1099
1118
}
1100
1119
1101
1120
/// <summary>
@@ -1107,6 +1126,18 @@ public void Add(string filenameCanonical, FileMetadataByVersion metadataByVersio
1107
1126
var existingMetadataByVersion = FindMetadataByVersion ( filenameCanonical , true ) ;
1108
1127
foreach ( var metadata in metadataByVersion . Values ) {
1109
1128
existingMetadataByVersion . Add ( metadata ) ;
1129
+ UpdateMetadataByFilename ( metadata ) ;
1130
+ }
1131
+ }
1132
+
1133
+ /// <summary>
1134
+ /// Update the mapping of filename to metadata.
1135
+ /// </summary>
1136
+ /// <param name="metadata">File metadata to add to the set.</param>
1137
+ private void UpdateMetadataByFilename ( FileMetadata metadata ) {
1138
+ metadataByFilename [ metadata . filename ] = metadata ;
1139
+ if ( ! String . IsNullOrEmpty ( metadata . exportPath ) ) {
1140
+ metadataByFilename [ metadata . exportPath ] = metadata ;
1110
1141
}
1111
1142
}
1112
1143
@@ -1121,8 +1152,11 @@ public void Add(string filenameCanonical, FileMetadataByVersion metadataByVersio
1121
1152
/// <returns>Reference to the metadata if successful, null otherwise.</returns>
1122
1153
public FileMetadata FindMetadata ( string filenameCanonical ,
1123
1154
long version ) {
1124
- var metadataByVersion = FindMetadataByVersion ( filenameCanonical , false ) ;
1125
1155
FileMetadata metadata ;
1156
+ if ( metadataByFilename . TryGetValue ( filenameCanonical , out metadata ) ) {
1157
+ return metadata ;
1158
+ }
1159
+ var metadataByVersion = FindMetadataByVersion ( filenameCanonical , false ) ;
1126
1160
if ( metadataByVersion != null ) {
1127
1161
metadata = version > 0 ? metadataByVersion [ version ] :
1128
1162
metadataByVersion . MostRecentVersion ;
0 commit comments