My summary of https://www.youtube.com/watch?v=IqrwPVtSHZI
TL;DR:
Rails has a library, ActiveSupport
, which adds methods to Ruby core classes. One of those methods is String#blank?
, which returns a boolean (sometimes I miss this convention in Rust, the ?
) if the whole string is whitespace or not. It looks like this: https://github.com/rails/rails/blob/b3eac823006eb6a346f88793aabef28a6d4f928c/activesupport/lib/active_support/core_ext/object/blank.rb#L99-L117
It's pretty slow. So Discourse (which you may know from {users,internals}.rust-lang.org) uses the fast_blank
gem, which provides this method via a C implementation instead. It looks like this: https://github.com/SamSaffron/fast_blank/blob/master/ext/fast_blank/fast_blank.c
For fun, Yehuda tried to re-write fast_blank
in Rust. Which looks like this: