"FIXME" Doesn't Always Mean "Fix Me"

If you browse through the Swift (or LLVM) codebase for a while, you’ll see a comment like this:

// FIXME: Dependencies should be de-duplicated at serialization time,
// not now.

My Little (String) Optimization, Part 2

Previously, I talked about how Clang is smart enough to optimize a series of comparisons against constant strings in C++ by starting out with a switch on the length. I left off with the idea that while this is good, you might be able to do better if your strings have a unique character at a certain offset. Today we’re going to see what that looks like.

My Little Optimization: The Compiler Is Magic

Today I had the idea to play with a pretty simple optimization problem: you have a string, and you want to see if it matches one of a set of known strings (down to the same Unicode codepoints, not caring about canonical equivalence). The naive way to do this would be to walk through and simply check every single string:

bool isOneOfTheStringsICareAbout(const std::string &s) {
  return s == "Battler" ||
         s == "George" ||
         s == "Jessica" ||
         s == "Maria" ||
         s == "Beatrice";
}

Older Posts

  1. 2018-02-26 Many-to-Many Protocols
  2. 2018-01-29 Color Palette #8
  3. 2017-09-07 The New Kingdom of Nouns
  4. 2017-09-05 Over-abstraction
  5. 2016-08-21 Macromancy, Part 2
  6. 2016-08-07 Macromancy
  7. 2016-06-19 Pronoun Buttons
  8. 2016-05-29 Webmailer's Update Bar
  9. 2016-05-23 So You Want to Be a (Compiler) Wizard
  10. 2015-12-29 Re: Contempt Culture
  11. 2015-11-18 Recommendations
  12. 2015-05-09 Nibblesort: Adventures in Optimization
  13. 2015-02-22 AlterConf SF/Oakland
  14. 2015-01-24 “Skip the FFI”
  15. 2012-12-08 How to Write a Checker in 24 Hours
  16. 2012-10-02 Git Tricks
  17. 2012-05-16 Big News
  18. 2012-04-26 Keyboard Adventures
  19. 2012-04-10 Mail Aliases
  20. 2011-08-14 Header Anchors: A Safari Extension
  21. 2011-08-10 "Little Big Details"
  22. 2011-07-29 Weak Linking
  23. 2011-07-25 Using Clang from SVN in Xcode
  24. 2011-07-22 rm vs. Time Machine
  25. 2011-07-14 Priorities
  26. 2011-06-30 Quick Look in TextMate
  27. 2011-06-27 git add
  28. 2011-06-20 Automatic Reference Counting
  29. 2011-06-16 Dealing with "Sandwich Code"
  30. 2011-06-05 gdba
  31. 2011-06-03 Chrome vs. Safari
  32. 2011-05-31 User-Side Troubleshooting
  33. 2011-05-30 Auspicious Continuation
  34. 2009-07-21 Scripting Bridge
  35. 2009-07-08 What Happened to Dockyard?
  36. 2009-06-26 Garbage Collectors and Stack Drawers
  37. 2009-06-21 Z shell
  38. 2009-05-22 “Several New Features”
  39. 2009-05-05 C++ Templates are Turing-Complete
  40. 2009-04-21 [Meme] How Many HTML Elements Can You Name in 5 Minutes?
  41. 2009-04-16 Safer Plugin Categories
  42. 2009-04-02 Hacking Safari 4...for Great Convenience
  43. 2009-03-27 Const Correctness
  44. 2009-03-19 Categories and +load
  45. 2009-03-15 Subversion Checksum Problems
  46. 2009-03-06 JavaScript Tetris
  47. 2008-09-04 Objective-J and Objective-C
  48. 2008-08-28 HTTPS and Name-based Virtual Hosting
  49. 2008-03-08 Alerts Without Apps (or nibs)
  50. 2008-01-14 NSNumber, CFNumber, and CFBoolean
  51. 2007-12-13 GenericToolbar and IB3
  52. 2007-10-27 Performance Optimization: Why We Can't Use valueForKeyPath:
  53. 2007-09-01 Short Xcode Tip: Plugins
  54. 2007-07-15 Port 25 Blocked?
  55. 2007-06-27 GenericToolbar Icon
  56. 2007-04-13 The Symbolism of Pretty URLS
  57. 2007-03-07 Flexible PHP
  58. 2007-01-12 Inauspicious Beginnings