Skip to content

Clean up some BDF quirks

akwizgran requested to merge bdf-cleanup into master

This branch cleans up some BDF quirks, adds convenience methods for 32-bit ints, and hopefully improves performance by making some frequently-used classes final.

  • When writing BDF, always use canonical form. Previously, the method for writing maps didn't ensure the entries were written in canonical order. BdfDictionaries would be written in canonical order as they sort their own entries, but other maps like TransportProperties might not be.
  • When reading BDF, default to requiring canonical form. An exception is needed for transport property updates, as the TransportProperties they contain may be in non-canonical order. After merging this branch, new updates will be in canonical form, so we can remove the exception from the validator after a migration period. We can remove it from the client when we eventually bump the major version.
  • When parsing UTF-8 strings, reject invalid characters instead of ignoring them. In practice, we're always calling these methods in places where a FormatException is expected for invalid input anyway.
  • Add some convenience methods for dealing with 32-bit ints. We use these a lot in practice. I didn't add similar method for 8-bit and 16-bit ints as we don't use them.
  • BdfList and BdfDictionary have three sets of getters: a basic getter that requires a value of the specified type; an optional getter that allows the value to be absent/null, but doesn't allow it to have a different type; and a default getter that returns a default value if the value is absent/null or has the wrong type. This MR changes the behaviour of the default getter so that it doesn't allow the value to have the wrong type, for consistency with the other getters. This simplifies the semantics and allows all three getters to share code.
  • Add comprehensive tests for BdfDictionary, like the ones for BdfList.
  • Make the BdfList, BdfDictionary, BdfReaderImpl and BdfWriterImpl classes final. We use these classes a lot, so any compiler optimisations that are enabled by making them final (eg method inlining) could make a big difference to performance.

Merge request reports