1. 16 Dec, 2012 20 commits
    • Tudor Bosman's avatar
      fix comments · 00126171
      Tudor Bosman authored
      Test Plan: no
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D629502
      00126171
    • Tudor Bosman's avatar
      add split operator · ed448247
      Tudor Bosman authored
      Summary:
      Also added eachAs (cast each value as a given type) and eachTo (use folly::to
      on each value)
      
      Test Plan: test added
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D628868
      ed448247
    • Tudor Bosman's avatar
      movify generators (but mostly operators) · 8d246c45
      Tudor Bosman authored
      Summary: Make things work with non-copyable generators.
      
      Test Plan: folly/experimental/test
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D628520
      8d246c45
    • Philip Pronin's avatar
      constexpr-ize folly/Bits.h · 6aa05bb9
      Philip Pronin authored
      Summary:
      Want to be able to call them from other constexpr functions
      and from within static_assert()s.
      
      Test Plan: compiled and ran folly tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D627413
      6aa05bb9
    • Chao Yang's avatar
      Fix example for folly::format · 91d0ef0e
      Chao Yang authored
      Summary: That's all.
      
      Test Plan: .
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D618824
      91d0ef0e
    • Tom Jackson's avatar
      Composed, for lightweight operator composition · c9ce99c0
      Tom Jackson authored
      Summary:
      Sometimes it'll be handy to have a custom operator which is little more than the
      composition of a few base operators. This makes that really easy to do, as shown
      in examples, tests, and benchmarks.
      
      Test Plan: Unit tests, benchmarks
      
      Reviewed By: rsagula@fb.com
      
      FB internal diff: D617152
      c9ce99c0
    • Tom Jackson's avatar
      Adding support for printing arbitrary pointers · 24f6247d
      Tom Jackson authored
      Summary: We should be able to print ##Foo*##, even if we can't print ##Foo##.
      
      Test Plan: Unit Tests.
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D625977
      24f6247d
    • Tom Jackson's avatar
      Enabling format("{}", format(...)) · 8ff3329c
      Tom Jackson authored
      Summary:
      If your format string ends up being conditional, it's handy to be able to chain
      together formatters.
      
      Test Plan: Unit tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D625502
      8ff3329c
    • Tudor Bosman's avatar
      add IOBuf::moveToFbString · aef2fb09
      Tudor Bosman authored
      Summary:
      Convert a IOBuf chain into a fbstring, with zero copies in the common case
      (unshared, unchained, no headroom) and one copy in all other cases.
      
      Test Plan: tests added
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D621210
      aef2fb09
    • Marcelo Juchem's avatar
      Clang complains about errors in folly String-inl.h and FBString.h (P1825995) · a8370f02
      Marcelo Juchem authored
      Summary: fixing clang errors (used clang 3.1)
      
      Test Plan: doh
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D622593
      a8370f02
    • Marcelo Juchem's avatar
      Adding usage example for BENCHMARK_DRAW_LINE() · 99f7266b
      Marcelo Juchem authored
      Summary:
      Yes, I admit, I was dumb enough to try it in a benchmark's
      body.
      
      Test Plan: review
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D622613
      99f7266b
    • Nicholas Ormrod's avatar
      Augment DynamicConverter's is_container check · c9f168a1
      Nicholas Ormrod authored
      Summary:
      DynamicConverter uses some simple heuristics to determine if a
      class is a container. One of those tests was to check that the
      constructor 'template <class Iterator> [container-name](Iterator first,
      Iterator last)' was present. That test was performed by checking if the
      class could be constructed by two parameters of some dummy class.
      
      However, it is possible to restrict the template parameter such that it
      only accepts iterators, and not any arbitrary dummy class. This would be
      useful, for example, to solve overload ambiguity with constructors like
      'vector(const T& val, size_type n)', where T and size_type are the same
      (see N3337 23.2.3 item 14). It also (I believe) produces more meaningful
      compiler errors when a non-iterator is supplied, since it errors at the
      function callsite instead of inside the constructor itself.
      
      The new FBVector implementation uses such a feature, and so checking for
      [container-name](dummy, dummy) will fail. Hence the dummy class has been
      upgraded to reverse_iterator<T*>, a valid iterator class which almost
      certainly does not have a specialized contructor in any class (and hence
      will not cause any visible change in class_is_container's value).
      
      Test Plan:
      Run DynamicConverterTest; it has tests for the correctness of
      class_is_container.
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D620607
      c9f168a1
    • Tudor Bosman's avatar
      ints used as flags (bitwise): so C · 96bd762f
      Tudor Bosman authored
      Summary:
      Changed communicate() flags from int to a class.
      Made Options and CommunicateFlags composable with |
      Simplified API so you don't have to type Subprocess::Options().stdout(Subprocess::PIPE)
      
      Test Plan: subprocess_test
      
      Reviewed By: chip@fb.com
      
      FB internal diff: D620186
      96bd762f
    • Tudor Bosman's avatar
      Retry wait() on EINTR; clean up signal handling · dcbf9149
      Tudor Bosman authored
      Test Plan: subprocess_test
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D619713
      dcbf9149
    • Tudor Bosman's avatar
      fix typos in comment; RV_* do not have to be public · d870f36c
      Tudor Bosman authored
      Test Plan: subprocess_test
      
      Reviewed By: chip@fb.com
      
      FB internal diff: D619189
      d870f36c
    • Tudor Bosman's avatar
      Subprocess library, modeled after python's subprocess module · 677bed09
      Tudor Bosman authored
      Summary:
      Surprised we don't have one.  The API is modeled after Python's
      subprocess module, http://docs.python.org/2/library/subprocess.html
      
      Inspired by
      https://www.facebook.com/groups/fbcode/permalink/445399858830192/, plus
      I needed this functionality now.
      
      Test Plan: test added
      
      Reviewed By: chip@fb.com
      
      FB internal diff: D614056
      677bed09
    • Misha Shneerson's avatar
      [Conv] Remove __int128 overload · f919a052
      Misha Shneerson authored
      Summary: parseInt128 is only available for GCC 4.7 and above.
      
      Test Plan: .
      
      Reviewed By: igorzi@fb.com
      
      FB internal diff: D618456
      
      Blame Revision: rFBCODEeaec97e2991f
      f919a052
    • Adam Simpkins's avatar
      update function_benchmark to test exception handling · 5196d1e2
      Adam Simpkins authored
      Summary:
      Add benchmarks for throwing an exception versus returning
      std::exception_ptr or other types of return values.
      
      Throwing an exception is very expensive.  Calling std::make_exception_ptr()
      without ever throwing is nearly as bad.
      
      The exc_ptr_param_return tests were the ones I was most interested in.
      (Accepting a std::exception_ptr* argument so the caller can indicate if they
      want to receive an exception or not.)  This is fast if the caller doesn't care
      about the exception value, but very slow if an error occurs and an
      exception_ptr is required.
      
      Test Plan:
      ======================================================================
      folly/test/function_benchmark/main.cpp    relative  time/iter  iters/s
      ======================================================================
      throw_exception                                        3.90us  256.25K
      catch_no_exception                                     1.88ns  533.25M
      return_exc_ptr                                         2.79us  357.85K
      exc_ptr_param_return                                   2.83us  353.25K
      exc_ptr_param_return_null                              2.25ns  444.38M
      return_string                                         69.39ns   14.41M
      return_string_noexcept                                69.39ns   14.41M
      return_code                                            1.50ns  666.54M
      return_code_noexcept                                   1.50ns  666.54M
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D616474
      5196d1e2
    • Misha Shneerson's avatar
      [Conv] MaxString specialization for __int128 · 5ec53c6f
      Misha Shneerson authored
      Summary: Just that.
      
      Test Plan: .
      
      Reviewed By: igorzi@fb.com
      
      FB internal diff: D613291
      5ec53c6f
    • Hari Manikarnika's avatar
      make folly::toJson retain non-ascii chars if encode_non_ascii is disabled · e18efdc4
      Hari Manikarnika authored
      Summary:
      folly::toJson as demonstrated by the test cases was wrongly encoding utf8 strings.
      specifically, a utf8 char made up of x bytes was encodeded into x unicode chars.
      
      for example, the char:
      \u2665
      which is made of 3 bytes:
      \xe2\x99\xa5
      was encoded correctly when using encode_non_ascii = true:
      "\u2665"
      but when encode_non_ascii = false, the json value was wrongly set as:
      "\u00e2\u0099\u00a5"
      
      because we use an signed char that wrongly detects non-readable chars with
      ascii value > 127 as control chars with ascii value < 32 (\t, \n, etc.)
      
      Test Plan: run the test
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D612782
      e18efdc4
  2. 29 Oct, 2012 8 commits
    • Tom Jackson's avatar
      Optional bugfixes · 6e230a3f
      Tom Jackson authored
      Summary: Tests were run in 'opt', which masked issues alterted by asserts.
      
      Test Plan: Unit tests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D611957
      6e230a3f
    • Xin Liu's avatar
      fixing double destruction of CSL::data_type · 368a5082
      Xin Liu authored
      Summary:
      the currently code calls both ~SkipListNode() and node->data_.~value_type()
      causes double destructing the object.
      
      Test Plan: adding dihde's testing code to a test case
      
      Reviewed By: emailweixu@fb.com
      
      FB internal diff: D612289
      368a5082
    • Marcelo Juchem's avatar
      fix Benchmark docs · 2940c186
      Marcelo Juchem authored
      Summary: fix Benchmark docs
      
      Test Plan: read
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D611820
      2940c186
    • Tom Jackson's avatar
      folly::gen, or Comprehensions->Folly · 506b9a32
      Tom Jackson authored
      Summary:
      Moving Comprehensions library into Folly and refactoring its interface to be much more modular and composable. There are now two core abstractions:
      
      # Generators: Standalone classes supporting ##apply()## and optionally ##foreach()##. These all inherit from ##GenImpl<T, Self>##.
      # Operators: Standalone classes which, when composed with a generator, produce a new generator. These all inherit from ##OperatorImpl<Self>##.
      
      These generators may be composed with ##operator|## overloads which only match ##const GenImpl<T, Self>&## on the left like ##gen | op##.  Additionally, generator may be consumed inline with ##gen | lambda## like ##gen | [](int x) { cout << x << endl; };##.
      
      With this design, new operators may be added very simply without modifying the core library and templates are instantiated only exactly as needed.
      
      Example:
      
      ```lang=cpp
      auto sum = seq(1, 10) | filter(isPrime) | sum;
      seq(1, 10) | [](int i) {
      cout << i << endl;
      };
      ```
      
      Test Plan: Unit tests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D542215
      506b9a32
    • Andrei Alexandrescu's avatar
      fbstring's front() and back() return by reference · 99d9bfdd
      Andrei Alexandrescu authored
      Summary: C++11 added front() and back() that return by reference. fbstring also added front() and back() as non-standard convenience functions, which returned by value. This diff aligns fbstring with the standard.
      
      Test Plan: added and ran unittest
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D607574
      99d9bfdd
    • Tom Jackson's avatar
      Optional · a8991a6b
      Tom Jackson authored
      Summary: Optional, like boost::optional, but with full rvalue support.
      
      Test Plan: Unit tests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D571810
      a8991a6b
    • Tudor Bosman's avatar
      Add a folly::exceptionStr overload · 91ee5f4b
      Tudor Bosman authored
      Summary: For std::exception_ptr.
      
      Test Plan: .
      
      Reviewed By: davejwatson@fb.com
      
      FB internal diff: D600345
      91ee5f4b
    • Sumeet Ungratwar's avatar
      Adding a general doc for traits provided in folly/Traits.h · 636f38ca
      Sumeet Ungratwar authored
      Summary:
      Understood how traits are implemented in folly/Traits.h and added
      examples on how to use them.
      
      Test Plan: no specific tests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D546631
      636f38ca
  3. 12 Oct, 2012 12 commits
    • Tudor Bosman's avatar
      Add SpookyHashV2 · 148cba11
      Tudor Bosman authored
      Summary:
      SpookyHashV2 is backwards incompatible with V1.  I renamed the existing
      SpookyHash class to SpookyHashV1 (and fixed all uses); the new class is
      called SpookyHashV2.
      
      From http://burtleburtle.net/bob/hash/spooky.html:
      
      Both V1 and V2 pass all the tests. V2 corrects two oversights in V1:
      
      In the short hash, there was a d = length that should have been d += length,
      which means some entropy got dropped on the floor. It passed the tests anyhow,
      but fixing this probably means more distinct info from the message makes it
      into the result.
      
      The long hash always ended in mix()+end(), but only end() was needed. Removing
      the extra call to mix() makes all long hashes faster by a small constant
      amount.
      
      Test Plan: test added; unicorn compiles
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D597173
      148cba11
    • Wei Xu's avatar
      Fix fbstring hash · 05783709
      Wei Xu authored
      Summary: '\0' may actually be part of string. We cannot assume its null terminated and should use another form of fnv32.
      
      Test Plan: FBStringTest
      
      Reviewed By: xliux@fb.com
      
      FB internal diff: D595287
      05783709
    • Rajat Goel's avatar
      Just trying out one more combination · 1fd9e62b
      Rajat Goel authored
      Summary:
      It seems it is not std::bind which is slow but the construction of
      std::function from std::bind that is slow.
      
      Test Plan: ran benchmarks
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D581967
      1fd9e62b
    • Jonathan Coens's avatar
      Get total memory currently allocated by an Arena allocator · 32801ac2
      Jonathan Coens authored
      Summary: The Arena allocator knows how much memory it's using up, so create a function that allows clients to figure out how much it's using. Also create a unit test to sanity check this stuff.
      
      Test Plan: folly/test/ArenaTest.cpp
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D579399
      32801ac2
    • Anton Likhtarov's avatar
      folly/json: serialize \r and \n as \r and \n · 49ccc34f
      Anton Likhtarov authored
      Summary:
      Background: we want to use folly::json but not change the way data is represented.
      Since we need to store \r and \n in strings and the library we're currently using does this,
      let's do it in folly too.
      
      Test Plan: unit tests pass
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D584960
      49ccc34f
    • Ashoat Tevosyan's avatar
      Add DynamicConverters for const strings. · 981ed984
      Ashoat Tevosyan authored
      Summary: These are necessary for string-keyed maps, since maps const their keys.
      
      Test Plan: I wrote a test.
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D582283
      981ed984
    • Andrew Tulloch's avatar
      Update folly/docs/Synchronized.md · 49417268
      Andrew Tulloch authored
      Summary:
      Fixed escaping bug where the `>` in `operator->` was
      interpreted as starting a code block.  Folly github pull #15.
      
      Test Plan: no
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D582873
      49417268
    • Jordan DeLong's avatar
      Add a FAQ item about dynamic strings · e825366c
      Jordan DeLong authored
      Summary:
      After a conversation with njormrod I remembered why we didn't
      do this.  Let's document it.
      
      Test Plan: It's docs.
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D582651
      e825366c
    • Philip Pronin's avatar
      SpinLockArray · 992f3b81
      Philip Pronin authored
      Summary:
      Array of spinlocks where each one is padded to prevent false
      sharing.
      
      Useful for shard-based locking implementations in environments where
      contention is unlikely.
      
      Test Plan: ran tests in 'common'
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D582149
      992f3b81
    • Andrei Alexandrescu's avatar
      Better unsigned to string conversion · 43bdc5d7
      Andrei Alexandrescu authored
      Summary:
      In https://phabricator.fb.com/D511928 Brian mentioned the current API for string append is insufficient for appending to a buffer. That made me curious about the relative performance of classic and table-based number to ASCII conversions.
      
      The results were interesting as on the average (over all digit lengths) the table-based conversion was faster, but performance was lackluster (in the worst case half as fast as the classic implementation) for large numbers, I presume due to the cache misses incurred by the tables.
      
      This diff proposes an improved unsigned-to-ASCII primitive that is much faster than both table-based (previous Folly) and classic primitive. The key is a fast digits10() implementation that precomputes the space required by the conversion. After that, the digits are issued in place, no more reverse required. The new routine is up to 14x faster than the classic implementation, depending on the number of digits (benchmarks in comments).
      
      Adding a few people who may be interested in the matter. Brian, thanks for bringing this matter up; if this gets in you may want to use the folly routine in proxygen.
      
      Test Plan: unittest and benchmarks.
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D515572
      43bdc5d7
    • Jeremy Lilley's avatar
      Fix push_back() to shared fbstring bug. · 3a5767e7
      Jeremy Lilley authored
      Summary:
      The following asserts:
      fbstring str(1337, 'f');
      fbstring cp = str;
      cp.push_back('f');
      
      This is problematic since ml_.capacity() != capacity() inside fbstring_core
      for shared strings, which causes us not to un-share prior to push_back.
      
      Test Plan: Existing tests, add unittest case.
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D580267
      3a5767e7
    • Lucian Grijincu's avatar
      folly: Range: implement find_first_of and optimize qfind(Range, char) · 0010b30e
      Lucian Grijincu authored
      Summary:
      implement ##find_first_of## and optimize ##Range.find(char)##
      
      ============================================================================
      folly/test/RangeBenchmark.cpp                   relative  time/iter  iters/s
      ============================================================================
      LongFindSingleCharDirect                                     2.76ms   362.63
      LongFindSingleCharRange                           15.88%    17.37ms    57.58
      ShortFindSingleCharDirect                                   53.41fs   18.72T
      ShortFindSingleCharRange                           0.00%    29.22ns   34.22M
      ============================================================================
      
      Test Plan:
      - added new tests
      
      - ran all folly tests
      
      fbconfig -r folly/ && mkk runtests_opt
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D576720
      0010b30e