Skip to content

Commit 862e1e3

Browse files
committed
switch to TryGetValue for PathName class
1 parent 6a9875e commit 862e1e3

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

FlashpointSecurePlayer/Shared.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,18 +1973,21 @@ public class PathNamesShort {
19731973

19741974
public string this[string longPath] {
19751975
get {
1976-
if (!pathNamesShort.ContainsKey(longPath)) {
1977-
StringBuilder shortPath = new StringBuilder(MAX_PATH);
1976+
pathNamesShort.TryGetValue(longPath, out string pathNameShort);
19781977

1979-
if (GetShortPathName(longPath, shortPath, (uint)shortPath.Capacity) >= shortPath.Capacity) {
1980-
return null;
1981-
}
1982-
1983-
string pathNameShort = shortPath.ToString();
1984-
pathNamesShort[longPath] = pathNameShort;
1978+
if (pathNameShort != null) {
19851979
return pathNameShort;
19861980
}
1987-
return pathNamesShort[longPath];
1981+
1982+
StringBuilder shortPath = new StringBuilder(MAX_PATH);
1983+
1984+
if (GetShortPathName(longPath, shortPath, (uint)shortPath.Capacity) >= shortPath.Capacity) {
1985+
return null;
1986+
}
1987+
1988+
pathNameShort = shortPath.ToString();
1989+
pathNamesShort[longPath] = pathNameShort;
1990+
return pathNameShort;
19881991
}
19891992
}
19901993
}
@@ -1994,18 +1997,21 @@ public class PathNamesLong {
19941997

19951998
public string this[string shortPath] {
19961999
get {
1997-
if (!pathNamesLong.ContainsKey(shortPath)) {
1998-
StringBuilder longPath = new StringBuilder(MAX_PATH);
2000+
pathNamesLong.TryGetValue(shortPath, out string pathNameLong);
19992001

2000-
if (GetLongPathName(shortPath, longPath, (uint)longPath.Capacity) >= longPath.Capacity) {
2001-
return null;
2002-
}
2003-
2004-
string pathNameLong = longPath.ToString();
2005-
pathNamesLong[shortPath] = pathNameLong;
2002+
if (pathNameLong != null) {
20062003
return pathNameLong;
20072004
}
2008-
return pathNamesLong[shortPath];
2005+
2006+
StringBuilder longPath = new StringBuilder(MAX_PATH);
2007+
2008+
if (GetLongPathName(shortPath, longPath, (uint)longPath.Capacity) >= longPath.Capacity) {
2009+
return null;
2010+
}
2011+
2012+
pathNameLong = longPath.ToString();
2013+
pathNamesLong[shortPath] = pathNameLong;
2014+
return pathNameLong;
20092015
}
20102016
}
20112017
}

0 commit comments

Comments
 (0)