Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7522c92837f2
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d0f59ca12318
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 5, 2021

  1. Copy the full SHA
    782dd0d View commit details
  2. order

    eggrobin committed Dec 5, 2021
    Copy the full SHA
    5a28609 View commit details
  3. Merge pull request #3227 from eggrobin/3226

    Mirror the overloads of Localizer.Format in LRUCache.Get and L10n.CacheFormat
    pleroy authored Dec 5, 2021
    Copy the full SHA
    d0f59ca View commit details
Showing with 20 additions and 4 deletions.
  1. +9 −0 ksp_plugin_adapter/localization_extensions.cs
  2. +11 −4 ksp_plugin_adapter/lru_cache.cs
9 changes: 9 additions & 0 deletions ksp_plugin_adapter/localization_extensions.cs
Original file line number Diff line number Diff line change
@@ -134,6 +134,15 @@ public static string CelestialStringOrNull(string template,
FormatOrNull(template, names));
}

public static string CacheFormat(string name) {
return lru_cache_.Get(name, () => Localizer.Format(name));
}

public static string CacheFormat(string name, params string[] args) {
return lru_cache_.Get(name, args,
() => Localizer.Format(name, args));
}

public static string CacheFormat(string name, params object[] args) {
return lru_cache_.Get(name, args,
() => Localizer.Format(name, args));
15 changes: 11 additions & 4 deletions ksp_plugin_adapter/lru_cache.cs
Original file line number Diff line number Diff line change
@@ -8,7 +8,11 @@ namespace principia {
namespace ksp_plugin_adapter {

class LRUCache {
public string Get(string name, object[] args, Func<string> compute_value) {
public string Get(string name, Func<string> compute_value) {
return Get(name, new string[]{}, compute_value);
}

public string Get(string name, string[] args, Func<string> compute_value) {
string key = MakeKey(name, args);
Entry entry;
if (cache_.TryGetValue(key, out entry)) {
@@ -30,10 +34,13 @@ public string Get(string name, object[] args, Func<string> compute_value) {
return entry.value;
}

public string MakeKey(string name, object[] args) {
public string Get(string name, object[] args, Func<string> compute_value) {
return Get(name, (from arg in args select arg.ToString()).ToArray(), compute_value);
}

public string MakeKey(string name, string[] args) {
string unit_separator = "\x1F";
return name + unit_separator +
string.Join(unit_separator, from arg in args select arg.ToString());
return name + unit_separator + string.Join(unit_separator, args);
}

private class Entry {