ckerr

#46939: refactor: add gin_helper::Dictionary::ValueOrDefault()

Merged
Created: May 5, 2025, 3:42:39 PM
Merged: May 6, 2025, 3:20:12 PM
7 comments
Target: main

Description of Change

Add gin_helper::Dictionary::ValueOrDefault(), a convenience function for using a default value if the specified key isn't in the dictionary.

tldr:

-  int foo = 23;
-  options.Get(options::kFoo &foo);
+  const int foo = options.ValueOrDefault(options::kFoo, 23);

This is an improvement because it's more const-friendly and more concise.

In some cases, you can also eliminate the variable altogether:

-  int foo = 23;
-  options.Get(options::kFoo, &foo);
-  dict.Set("foo", foo);
+  dict.Set("foo", options.ValueOrDefault(options::kFoo, 23));

Checklist

Release Notes

Notes: none.

Backports

35-x-y
Merged
PR Number
#47203
Merged At
May 22, 2025, 5:35:57 AM
Released In
v35.5.0
Release Date
May 28, 2025, 11:03:13 AM
36-x-y
Merged
PR Number
#46968
Merged At
May 6, 2025, 6:50:12 PM
Released In
v36.2.0
Release Date
May 7, 2025, 11:02:14 AM
37-x-y
Merged
PR Number
#46969
Merged At
May 6, 2025, 7:11:30 PM
Released In
v37.0.0-alpha.4
Release Date
May 12, 2025, 8:31:44 AM

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron