Improve remarkup performance (libphutil)

Summary:
As we've moved more logic post-cache, we've started paying a higher price for it. Reorganize some bits of the rendering pipeline so we do less work.

Mostly, this just means that we don't call `setEngine()` unnecessarily 20,000 times, and don't make multiple postprocessing passes for rules in more than one block.

Test Plan: Unit tests; profiled a 75% reduction of cost in Conpherence.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5511
add Filesystem::writeFileIfChanged

Summary:
porting this from FB to libphutil.  We've been using this
internally for a couple of months.  The intention is to ensure that
build steps atomically write the entire contents from the perspective
of readers.

For example, we had cases where reasonably large PHP source files were
being generated concurrently with another process attempting to read
the file.  Since the file was in the middle of being re-written, the
reader hit a parse error.

While this doesn't guarantee consistency from an overall code-base
perspective, it does mean that the contents of the file are internally
consistent.

Since we use this method in build steps, we only replace the file if
its contents are different.  This avoids touching the file and causing
a false rebuild of the dependents.  In this scenario, we assume that
some other mechanism exists to ensure that there is only one writer
(such as locking in the build scripts), and that it is "OK" for there
to be concurrent readers.

Test Plan:
It's a port from our Filesystem library.  I tried it out
from our build workflow.  We already found and fixed the umask bug ;-)

Reviewers: nh, epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5523
Fix uri generation when provided relative path

Summary:
If setPath is called on a uri object like
`$uri = id(new PhutilURI('foo.example'))->setPath('bar')`, the uri generated
by the __toString method does not put a slash between the domain and the path,
resulting in `foo.examplebar` instead of `foo.example/bar`.

Test Plan: arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5527