Simplify code a bit to avoid constant null checking and also take advantage of
the fact that HashSet.Add returns if the value was added or not (to avoid a
Contains check).
This commit is contained in:
Rolf Bjarne Kvinge 2017-01-16 18:35:28 +01:00 коммит произвёл GitHub
Родитель 6fe1c9feab
Коммит d6c2422fcf
1 изменённых файлов: 10 добавлений и 35 удалений

Просмотреть файл

@ -42,10 +42,10 @@ namespace Xamarin.Bundler {
public bool EnableCxx; public bool EnableCxx;
public bool NeedsGccExceptionHandling; public bool NeedsGccExceptionHandling;
public bool ForceLoad; public bool ForceLoad;
public HashSet<string> Frameworks; public HashSet<string> Frameworks = new HashSet<string> ();
public HashSet<string> WeakFrameworks; public HashSet<string> WeakFrameworks = new HashSet<string> ();
public List<string> LinkerFlags; // list of extra linker flags public List<string> LinkerFlags = new List<string> (); // list of extra linker flags
public List<string> LinkWith; // list of paths to native libraries to link with. public List<string> LinkWith = new List<string> (); // list of paths to native libraries to link with.
public HashSet<ModuleReference> UnresolvedModuleReferences; public HashSet<ModuleReference> UnresolvedModuleReferences;
bool? symbols_loaded; bool? symbols_loaded;
@ -203,8 +203,6 @@ namespace Xamarin.Bundler {
throw ErrorHelper.CreateError (1303, "Could not decompress the native framework '{0}' from '{1}'. Please review the build log for more information from the native 'unzip' command.", libraryName, zipPath); throw ErrorHelper.CreateError (1303, "Could not decompress the native framework '{0}' from '{1}'. Please review the build log for more information from the native 'unzip' command.", libraryName, zipPath);
} }
if (Frameworks == null)
Frameworks = new HashSet<string> ();
Frameworks.Add (path); Frameworks.Add (path);
} else { } else {
if (!Application.IsUptodate (FullPath, path)) { if (!Application.IsUptodate (FullPath, path)) {
@ -221,8 +219,6 @@ namespace Xamarin.Bundler {
"(if the assembly was built using a binding project, the native library must be included in the project, and its Build Action must be 'ObjcBindingNativeLibrary').", "(if the assembly was built using a binding project, the native library must be included in the project, and its Build Action must be 'ObjcBindingNativeLibrary').",
libraryName, path); libraryName, path);
if (LinkWith == null)
LinkWith = new List<string> ();
LinkWith.Add (path); LinkWith.Add (path);
} }
} }
@ -334,37 +330,25 @@ namespace Xamarin.Bundler {
case "libsystem_kernel": case "libsystem_kernel":
break; break;
case "sqlite3": case "sqlite3":
if (LinkerFlags == null)
LinkerFlags = new List<string> ();
LinkerFlags.Add ("-lsqlite3"); LinkerFlags.Add ("-lsqlite3");
Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName);
break; break;
case "libsqlite3": case "libsqlite3":
// remove lib prefix // remove lib prefix
if (LinkerFlags == null)
LinkerFlags = new List<string> ();
LinkerFlags.Add ("-l" + file.Substring (3)); LinkerFlags.Add ("-l" + file.Substring (3));
Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName);
break; break;
case "libGLES": case "libGLES":
case "libGLESv2": case "libGLESv2":
// special case for OpenGLES.framework // special case for OpenGLES.framework
if (Frameworks == null) if (Frameworks.Add ("OpenGLES"))
Frameworks = new HashSet<string> ();
if (!Frameworks.Contains ("OpenGLES")) {
Frameworks.Add ("OpenGLES");
Driver.Log (3, "Linking with the framework OpenGLES because {0} is referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with the framework OpenGLES because {0} is referenced by a module reference in {1}", file, FileName);
}
break; break;
case "vImage": case "vImage":
case "vecLib": case "vecLib":
// sub-frameworks // sub-frameworks
if (Frameworks == null) if (Frameworks.Add ("Accelerate"))
Frameworks = new HashSet<string> ();
if (!Frameworks.Contains ("Accelerate")) {
Frameworks.Add ("Accelerate");
Driver.Log (3, "Linking with the framework Accelerate because {0} is referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with the framework Accelerate because {0} is referenced by a module reference in {1}", file, FileName);
}
break; break;
case "CoreAudioKit": case "CoreAudioKit":
case "Metal": case "Metal":
@ -374,31 +358,22 @@ namespace Xamarin.Bundler {
#if MTOUCH #if MTOUCH
if (!App.IsSimulatorBuild) { if (!App.IsSimulatorBuild) {
#endif #endif
if (Frameworks == null) if (Frameworks.Add (file))
Frameworks = new HashSet<string> ();
if (!Frameworks.Contains (file)) {
Frameworks.Add (file);
Driver.Log (3, "Linking with the framework {0} because it's referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with the framework {0} because it's referenced by a module reference in {1}", file, FileName);
}
#if MTOUCH #if MTOUCH
} }
#endif #endif
break; break;
case "openal32": case "openal32":
if (Frameworks == null) if (Frameworks.Add ("OpenAL"))
Frameworks = new HashSet<string> (); Driver.Log (3, "Linking with the framework OpenAL because {0} is referenced by a module reference in {1}", file, FileName);
Frameworks.Add ("OpenAL");
break; break;
default: default:
// detect frameworks // detect frameworks
int f = name.IndexOf (".framework/", StringComparison.Ordinal); int f = name.IndexOf (".framework/", StringComparison.Ordinal);
if (f > 0) { if (f > 0) {
if (Frameworks == null) if (Frameworks.Add (file))
Frameworks = new HashSet<string> ();
if (!Frameworks.Contains (file)) {
Frameworks.Add (file);
Driver.Log (3, "Linking with the framework {0} because it's referenced by a module reference in {1}", file, FileName); Driver.Log (3, "Linking with the framework {0} because it's referenced by a module reference in {1}", file, FileName);
}
} else { } else {
if (UnresolvedModuleReferences == null) if (UnresolvedModuleReferences == null)
UnresolvedModuleReferences = new HashSet<ModuleReference> (); UnresolvedModuleReferences = new HashSet<ModuleReference> ();