icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Additional ZeroMap2d and ZeroMapKV cleanup

Open sffc opened this issue 3 years ago • 6 comments

Cleanup from comments in PRs #1876 and #1901:

  • [x] Figure out 'static bound on the const constructor for BorrowedVariant https://github.com/unicode-org/icu4x/pull/1901#discussion_r876405607
  • [x] Add Slice to ZeroMapKV https://github.com/unicode-org/icu4x/pull/1901#discussion_r876406165
  • [x] Rename BorrowedVariant to SliceVariant https://github.com/unicode-org/icu4x/pull/1901#discussion_r876406310
  • [x] Remove the trait BorrowedZeroVecLike https://github.com/unicode-org/icu4x/pull/1901#discussion_r876406813
  • [ ] Remove the .get() and .get_copied() methods of ZeroMap2d, remove KeyError, change the cursor methods to have those names, and update call sites https://github.com/unicode-org/icu4x/pull/1876#issuecomment-1123711791
  • [ ] ~Consider removing zvl_binary_search and zvl_binary_search_in_range and rely on only the predicate-based versions of them~ (No, because it's theoretically possible that the non-predicate versions could be faster)
  • [x] Fix typo: https://github.com/unicode-org/icu4x/pull/1876#discussion_r889060576

sffc avatar Jun 03 '22 06:06 sffc

I ended up leaving the 'static bound for SliceVariant where it is, on the methods that need to call zvl_new_borrowed, because putting it on the associated type itself requires T: 'static due to https://github.com/rust-lang/rust/issues/92094, even though it shouldn't, since T::ULE is the thing that needs to be 'static.

sffc avatar Jun 08 '22 18:06 sffc

@robertbastian I kind-of like having an all-in-one ZeroMap2d::get(k0, k1). How strongly do you feel about getting rid of that method and keeping the cursor methods named get0 and get1? If we keep the all-in-one get, I may make it return an Option since KeyError is no longer necessary.

sffc avatar Jul 27 '22 01:07 sffc

I think get0 and get1 are more important APIs as they allow more client flexibility and force separate error handling, so I'd like them to have the standard names (standard as in a nested HashMap).

map.get(k0).and_then(|m| m.get(k1)) isn't too verbose if you really don't care where the None comes from.

robertbastian avatar Jul 27 '22 09:07 robertbastian

ok, here's what I will do then:

  • Rename get and get_copied to get_2d and get_copied_2d
  • Rename get0 and iter0 to get and iter
  • Rename get1, iter1, and get1_copied to get, iter, and get_copied

sffc avatar Jul 27 '22 15:07 sffc

Works for me

robertbastian avatar Jul 27 '22 15:07 robertbastian

I realized that this is a Utilities 1.0 issue, not an ICU4X 1.0 issue. I did half of the work in #2279 and I will do the other half at a later time.

sffc avatar Jul 31 '22 05:07 sffc