From 49b9c584d4d74ec1d0daf428a485210565935bd3 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Tue, 20 Sep 2016 16:59:25 +0100 Subject: [PATCH] ubuntu: Don't reference all packages, just the ones we need (langpacks) --- source/backends/ubuntu/ubupkg.d | 16 +++++++++++----- source/backends/ubuntu/ubupkgindex.d | 25 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/source/backends/ubuntu/ubupkg.d b/source/backends/ubuntu/ubupkg.d index 77dc81f2..d69f3ba6 100644 --- a/source/backends/ubuntu/ubupkg.d +++ b/source/backends/ubuntu/ubupkg.d @@ -39,12 +39,12 @@ extern (C) char *bindtextdomain (const char *domainname, const char *dirName) no class UbuntuPackage : DebPackage { - this (string pname, string pver, string parch, string globalTmpDir, ref Array!Package allPackages) + this (string pname, string pver, string parch, string globalTmpDir, ref Array!Package langpacks) { this.globalTmpDir = globalTmpDir; this.langpackDir = buildPath (globalTmpDir, "langpacks"); this.localeDir = buildPath (langpackDir, "locales"); - this.allPackages = allPackages; + this.langpacks = langpacks; super (pname, pver, parch); } @@ -78,7 +78,7 @@ private: string langpackDir; string localeDir; string[] langpackLocales; - Array!Package allPackages; + Array!Package langpacks; private void extractLangpacks () { @@ -97,8 +97,8 @@ private: langpackDir.mkdirRecurse (); - foreach (pkg; allPackages) { - if (!pkg.name.startsWith ("language-pack") || pkg.name in extracted) + foreach (ref pkg; langpacks) { + if (pkg.name in extracted) continue; auto upkg = to!UbuntuPackage (pkg); @@ -109,6 +109,9 @@ private: extracted[pkg.name] = true; } + // get back the memory + langpacks.clear; + auto supportedd = buildPath (langpackDir, "var", "lib", "locales", "supported.d"); localeDir.mkdirRecurse (); @@ -133,6 +136,9 @@ private: scope (exit) wait (pid); } } + } else { + // we don't need it; we've already extracted the langpacks + langpacks.clear; } if (langpackLocales is null) diff --git a/source/backends/ubuntu/ubupkgindex.d b/source/backends/ubuntu/ubupkgindex.d index 278714eb..c7a4b628 100644 --- a/source/backends/ubuntu/ubupkgindex.d +++ b/source/backends/ubuntu/ubupkgindex.d @@ -30,34 +30,43 @@ class UbuntuPackageIndex : DebianPackageIndex { private: - Array!Package allPackages; + Array!Package langpacks; public: this (string dir) { /* * UbuntuPackage needs to extract the langpacks, so we give it an array - * of all packages. We don't do this here, as you migh think makes - * sense, because it is a very expensive operation and we want to avoid - * doing it if it's not necessary (when no packages being processed are - * using langpacks). + * of langpacks. There is a small overhead when computing this array + * which might be unnecessary if no processed packages are using + * langpacks, but otherwise we need to keep a reference to all packages + * around, which is very expensive. */ - allPackages = make!(Array!Package); + langpacks = make!(Array!Package); super (dir); } override DebPackage newPackage (string name, string ver, string arch) { - return new UbuntuPackage (name, ver, arch, tmpDir, allPackages); + return new UbuntuPackage (name, ver, arch, tmpDir, langpacks); } override Package[] packagesFor (string suite, string section, string arch) { + import std.string : startsWith; + auto pkgs = super.packagesFor (suite, section, arch); + auto pkgslangpacks = appender!(Package[]); + + foreach (ref pkg; pkgs) { + if (pkg.name.startsWith ("language-pack-")) + pkgslangpacks ~= pkg; + } + + langpacks ~= pkgslangpacks.data; - allPackages ~= pkgs; return pkgs; } }