tarcieri/nio4r — pull request #14 by loganb (2012-12-03 00:15:06+00:00)
Title: Factor code for Maximal Ruby/Minimal C

Hello,

This pull request isn't ready yet, but I wanted to get some feedback before continuing. I wanted to make some edits to nio4r to support changing the interest set on an extant Monitor, but found the 3-parallel-implementations paradigm frustrating. Also, there seemed to be many methods in C that were significantly longer than their Ruby counterparts.

I've started to refactor the code to maximize the use of Ruby and minimize the use of C. I believe when I'm finished, a decent chunk of the code will become Ruby-only and shared across all implementations of the event loop. I believe this will make the code base smaller and more easily maintained. I am only part way through, so I expect the savings to grow as I continue.

Advantages:
- Less Code (currently ~200 lines, or 2%)
- Locking/Setters/Getters in Ruby instead of C/Java (more maintainable)
- More code sharing (Monitor becomes completely shared across impls)
- Less internal references, e.g. pointers only visible in C, and smaller C structs, no cross-file methods

To do:
- Factor Ruby/Java versions (which will mean more code savings)
- Fixup locking (will wrap methods from Ruby side, remove all C locking code)
- Test on all platforms

I expect when I'm done, I'll have removed another few hundred lines of code. Currently, all tests pass for the libev backend on Ruby 1.9.3.

I realize this will be a big pull request, so let me know what you think and if there's anything I can do to make its digestion easier.