1. 27 Mar, 2013 6 commits
    • Owen Yamauchi's avatar
      Compile out GroupVarint on non-Intel · 5d43d2ab
      Owen Yamauchi authored
      Summary:
      Compile out instead of erroring.
      
      In an ideal world, we'd have a fallback that would work across platforms
      (i.e. no SSE, no unaligned 32-bit writes etc.) and compile some version
      of GroupVarint in all environments. I actually tried this; the SSE stuff
      is all behind #if __SSSE3__ already, so I thought it could work (modulo
      the unaligned-writes problem). I ran into problems with the
      SSSE3-vs.-not distinction that @simpkins alluded to in D652764, and
      decided I'd rather not open that can of worms at the moment.
      
      Test Plan:
      fbmake runtests. Manually force the #ifs to false and make
      sure fbmake runtests still passes (although GroupVarintTest is empty).
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D747150
      5d43d2ab
    • Louis Brandy's avatar
      StlAllocator.h + MakeUnique.h -> Memory.h · 244a8996
      Louis Brandy authored
      Summary:
      Go with the fat header approach. Merge these two into Memory.h. We could, potentially, include Malloc.h as well, but it fbstring header uses the once define for some special magic. Leave it alone for now.
      
      An alternate approach might be moving all three leaner headers into a `memory/` subdir with `folly/Memory.h` just #including the three.
      
      Test Plan:
      fbconfig folly/tests && fbmake runtests_opt
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D745873
      244a8996
    • Mike Curtiss's avatar
      HACK: Static detection of infinite sequences · ae4fa388
      Mike Curtiss authored
      Summary:
      Certain operations should not be performed on infinite sequences
      (e.g. sorting, left-folds, summation).  In some cases, we can
      detect that a sequence is infinite at compile-time and provide
      a static_assert to prevent such dangerous operations.
      
      Test Plan:
      Manually created cases where the operation should
      be disallowed.  Compiler correctly raised an error.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D740011
      ae4fa388
    • Louis Brandy's avatar
      Copyright 2012 -> 2013 · 5c77fedb
      Louis Brandy authored
      Summary: See title.
      
      Test Plan: Inspection.
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D745883
      5c77fedb
    • Hans Fugal's avatar
      IOBuf::getIov · 51f6dea4
      Hans Fugal authored
      Summary:
      Generate an `fbvector` of `struct iovec` suitable for using with `writev` or
      `sendmsg`.
      
      This code is pretty straightforward, but Adam pointed out that something along
      these lines has already been done in thrift, so I followed that code closely.
      http://fburl.com/11586814
      
      Test Plan:
      fbmake runtests
      
      I am using also this in a prototype and it's working there.
      
      Reviewed By: agartrell@fb.com
      
      FB internal diff: D744055
      51f6dea4
    • Alessandro Salvatori's avatar
      allow to dequeue the first IOBuf in an IOBufQueue · 33a4bac6
      Alessandro Salvatori authored
      Summary: allow to dequeue the first IOBuf in an IOBufQueue
      
      Test Plan: throughly tested with some dependent code in proxygen
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D732484
      33a4bac6
  2. 19 Mar, 2013 34 commits
    • Mike Curtiss's avatar
      Use aligned loads for Range::find_first_of · 81af5c4c
      Mike Curtiss authored
      Summary:
      Aligned loads are faster on some architectures. Let's refactor
      qfind_first_of so that it uses aligned loads when possible.
      
      Also modify the benchmarks to account for begin/end-of-string
      logic.
      
      Test Plan:
      Tests pass. Updated benchmarks.  Generally seeing a 5-20%
      speed-up, depending on the situation.
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D720369
      81af5c4c
    • Tom Jackson's avatar
      Short-circuit operator== based on size() · df1ffef3
      Tom Jackson authored
      Summary:
      We don't do this today, but it looks like std::string does. For longer, similar strings, this is a big win.
      
      Before:
      
      ```lang=text
      ============================================================================
      ./folly/test/FBStringTestBenchmarks.cpp.h       relative  time/iter  iters/s
      ============================================================================
      BM_equality_string(65536)                                    5.13ms   194.87
      BM_equality_fbstring(65536)                                 11.34ms    88.18
      ============================================================================
      ```
      
      After:
      
      ```lang=text
      ============================================================================
      ./folly/test/FBStringTestBenchmarks.cpp.h       relative  time/iter  iters/s
      ============================================================================
      BM_equality_string(65536)                                    5.01ms   199.74
      BM_equality_fbstring(65536)                                  6.63ms   150.78
      ============================================================================
      ```
      
      Test Plan: Benchmark, unit  tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D737482
      df1ffef3
    • Tom Jackson's avatar
      Fix unsplit(", ") · 76d60885
      Tom Jackson authored
      Summary: Otherwise you get errors like `error: array used as initializer ./folly/experimental/StringGen-inl.h: In constructor ‘folly::gen::detail::UnsplitBuffer<Delimiter, OutputBuffer>::UnsplitBuffer(const Delimiter&, OutputBuffer*) [with Delimiter = char [3] ...]`, since literal strings bind as reference to fixed-length character arrays. Providing an explicit overload for `const char*` fixes this.
      
      Test Plan: Unit tests
      
      Reviewed By: tulloch@fb.com
      
      FB internal diff: D737117
      76d60885
    • Marcelo Juchem's avatar
      adding is_non_positive traits · 1bf1654c
      Marcelo Juchem authored
      Summary:
      template <typename SomeInt>
      void foo(SomeInt x) {
      // yields an error in clang when SomeInt is unsigned and -Werror is used
      if(x <= 0) {
      //...
      }
      }
      
      Test Plan: added unit tests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D735735
      1bf1654c
    • David Vickrey's avatar
      Make hash_combine accept a configurable hash function · e4f530f8
      David Vickrey authored
      Summary:
      std::hash is not awesome and not configurable.  Typical cases you might want to customize are:
      string: I happen to know that fnv isn't super awesome, for example, and that's what folly uses for std::hash fbstring.
      pointers: you may want to hash the contents of the pointer instead of the address for certain types.
      
      This is a very simple diff that lets you do that.  It provides StdHasher that passes through to std::hash and uses that for hash_combine, so this should be 100% backward compatible.
      
      Test Plan: test_hash.  I will add another test for using a hasher besides StdHasher shortly.
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D733899
      e4f530f8
    • Tom Jackson's avatar
      Fixing namespace for GeneratorBuilder, more moves for Params · 9fb46d14
      Tom Jackson authored
      Summary:
      GENERATOR was broken if you didn't `using namespace folly::gen`, and
      we're still copying quite a few functors where we could move them.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D731253
      9fb46d14
    • Lovro Puzar's avatar
      Add explicit assignment operator definitions to Optional · fd20c97c
      Lovro Puzar authored
      Summary:
      See new test.  Under GCC 4.6 (which is what the folly tests build with) the old code works fine but under 4.7 building fails with:
      
      folly/test/OptionalTest.cpp: In member function ‘virtual void Optional_AssignmentContained_Test::TestBody()’:
      folly/test/OptionalTest.cpp:122:14: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’
      folly/test/OptionalTest.cpp:106:21: note: ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’ is implicitly deleted because the default definition would be ill-formed:
      folly/test/OptionalTest.cpp:106:21: error: use of deleted function ‘folly::Optional<int>& folly::Optional<int>::operator=(const folly::Optional<int>&)’
      In file included from folly/test/OptionalTest.cpp:17:0:
      ./folly/Optional.h:84:7: note: ‘folly::Optional<int>& folly::Optional<int>::operator=(const folly::Optional<int>&)’ is implicitly declared as deleted because ‘folly::Optional<int>’ declares a move constructor or move assignment operator
      folly/test/OptionalTest.cpp:129:30: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(ContainsOptional&&)’
      folly/test/OptionalTest.cpp:108:21: note: ‘ContainsOptional& ContainsOptional::operator=(ContainsOptional&&)’ is implicitly deleted because the default definition would be ill-formed:
      folly/test/OptionalTest.cpp:108:21: error: non-static data member ‘ContainsOptional::opt_’ does not have a move assignment operator or trivial copy assignment operator
      folly/test/OptionalTest.cpp:137:14: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’
      
      Test Plan:
      (1) fbconfig folly/test && fbmake dbg && _build/dbg/folly/test/optional_test
      (2) Remove folly/PLATFORM to build with gcc 4.7, then repeat (1).  Without the code fix, the new test fails to build.  With the fix, the test builds and runs fine.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D732402
      fd20c97c
    • Ben Gertzfield's avatar
      folly (easy): Disable GCC-specific warning disabling hacks in clang · d006f324
      Ben Gertzfield authored
      Summary:
      When compiling folly with clang, the compiler warns about our
      use of GCC-specific pragmas to silence incorrect compiler warnings:
      
      folly/Optional.h:79:33: warning: unknown warning group '-Wpragmas', ignored [-Wunknown-pragmas]
      folly/Optional.h:80:33: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-pragmas]
      
      Thankfully, those incorrect compiler warnings are not emitted by
      clang, so we can just disable the pragmas in clang.
      
      Test Plan:
      Built folly in gcc and ran it through clang. Warning above
      is gone.
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D733323
      d006f324
    • Tudor Bosman's avatar
      Add CHECK for out-of-range minRequests · 30313905
      Tudor Bosman authored
      Test Plan: async_io_test
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D730100
      30313905
    • Tom Jackson's avatar
      Remove File::tryOpen · a6fac16f
      Tom Jackson authored
      Summary:
      In hopes of keeping 'busywork' helpers out of folly, I've moved this
      closer to the code that needed to do this.
      
      Test Plan: Unit tests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D729194
      
      Blame Revision: D726916
      a6fac16f
    • Tom Jackson's avatar
      File::tryOpen · 9d6c66dd
      Tom Jackson authored
      Summary:
      Now that we have truthy files, it would be nice to be able to simply
      //try// opening files and return a possibly-initialized File.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D726916
      9d6c66dd
    • Tom Jackson's avatar
      Truthy File · 9d7cc509
      Tom Jackson authored
      Summary:
      File has a default constructor so it can be initialized late, but it
      doesn't have a good canonical way to see if it's been initialized. This adds an
      //explicit// operator bool so you can test files like `if (file) ...`.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D726914
      9d7cc509
    • Tudor Bosman's avatar
      Add resizing constructor to folly::padded::Adaptor · f4cbf351
      Tudor Bosman authored
      Summary: Added Adaptor(size_t, const value_type&)
      
      Test Plan: test added
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D726358
      f4cbf351
    • Tom Jackson's avatar
      Adding useful error message for File · 218b5231
      Tom Jackson authored
      Summary:
      'open() failed' isn't too helpful. Seeing a filename there is. So I
      added it.
      
      Test Plan: Unit test
      
      Reviewed By: mohittalwar@fb.com
      
      FB internal diff: D725204
      218b5231
    • Adam Simpkins's avatar
      provide a flag to control the minimum number of iterations · f0abc60e
      Adam Simpkins authored
      Summary:
      Add a --bm_min_iters flag to control the minimum number of iterations
      that the benchmark code starts with on each epoch.
      
      This can be used on benchmarks that test very cheap operations, but take
      a long time to set up.  Otherwise the benchmark code may have to retry
      many times before it hits a large enough number of iterations to get a
      meaningful result, and each time it still pays the fixed setup cost.
      
      This also helps with benchmarks when some of the setup cost cannot be
      hidden with BenchmarkSuspender for some reason.  --bm_min_iters can be
      set to a large enough value so that the extra startup cost will not
      affect the measurements too much.
      
      Test Plan:
      Used this with the thread local stats benchmark.  During setup/cleanup,
      this benchmark starts and synchronizes with many threads.  The entire
      setup time cannot be reliably hidden with BenchmarkSuspender; the
      synchronization between the threads takes a relatively long time
      compared to the cost of the operation being benchmarked.  --bm_min_iters
      allows a relatively high number of iterations to be used, masking this
      cost.
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D723304
      f0abc60e
    • Mike Curtiss's avatar
      folly::make_optional · 8c89c7dd
      Mike Curtiss authored
      Summary:
      Helper method for creating a folly::Optional<T> by just passing
      in a T reference.  Analogous to boost::make_optional.
      
      Test Plan: Added test case
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D721762
      8c89c7dd
    • Lucian Grijincu's avatar
      MemoryMapping::data() returns StringPiece ::range() returns ByteRange · cb610acb
      Lucian Grijincu authored
      Summary: MemoryMapping::data() returns StringPiece ::range() returns ByteRange
      
      Test Plan: tests
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D720985
      cb610acb
    • Owen Yamauchi's avatar
      Abstract ifunc support into a define · 3a976a95
      Owen Yamauchi authored
      Summary:
      There are platforms other than clang that don't support ifuncs. (The one
      I'm concerned about is ARM.) I changed the ifdef __clang__ around the
      ifunc attributes to be more abstract, so we can can pass in this flag on
      the command line, or use autoconf to detect it.
      
      Test Plan:
      fbmake runtests. Manually define HAVE_IFUNC 0 and make sure the
      popcount() and popcountll() functions get compiled as calls to
      popcount_builtin.
      
      Run autoreconf, ./configure, make sure the feature gets detected
      properly by looking at config.h.
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D712192
      3a976a95
    • Tom Jackson's avatar
      Renaming flag in MemoryMapping · d059cdd4
      Tom Jackson authored
      Summary:
      This flag conflicts with the flag with the same purpose in
      `common/files/MemoryMappedFile.cpp`. Just renaming it for now.
      
      Test Plan: Build
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D717067
      d059cdd4
    • Tom Jackson's avatar
      MemoryMapping · 2b8ea381
      Tom Jackson authored
      Summary: MemoryMapping is a C++ wrapper object around mmap. It works with `folly::File`s, and provides bitwise-range access for reading and writing files.
      
      Test Plan: Unit test
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D452384
      2b8ea381
    • Lucian Grijincu's avatar
      folly: AsyncIO: add debuging helper · 88b49f3e
      Lucian Grijincu authored
      Summary: Change State to enum class, and add debugging helper to AsyncIOOp and AsyncIO.
      
      Test Plan: n/a
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D715676
      88b49f3e
    • Tom Jackson's avatar
      folly/{experimental => .}/File · feca2a76
      Tom Jackson authored
      Summary: Moving File into `/folly`.
      
      Test Plan: Same unit tests, rebuild affected code outside folly.
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D714462
      feca2a76
    • Mike Curtiss's avatar
      Fix SIGSEGV in StringPiece::find_first_of · 4f7a54f6
      Mike Curtiss authored
      Summary:
      Our SSE version of find_first_of was reading past the end of
      the StringPiece in some cases, which (very rarely) caused a seg-fault
      when we were reading outside of our allotted virtual address space.
      
      Modify the code to never read past the end of the underlying buffers
      except when we think it's "safe" because we're still within the same
      page. (ASSUMPTION: if a process is allowed to read a byte within a
      page, then it is allowed to read _all_ bytes within that page.)
      
      Test Plan:
      Added tests that verify we won't go across page boundaries.
      
      Sadly, this code hurts our benchmarks -- sometimes by up to 50% for
      smaller strings.
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D707923
      
      Blame Revision: D638500
      4f7a54f6
    • Tudor Bosman's avatar
      Rework folly::AsyncIO interface to make it easier for other classes to use Op · a8b4b5ea
      Tudor Bosman authored
      Summary:
      AsyncIOOp no longer requires derivation to be able to use callbacks; the
      callback is passed in.  This makes composition easier (see AsyncIOQueue, added
      in this diff).
      
      Test Plan: async_io_test, test added
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D709648
      a8b4b5ea
    • Tudor Bosman's avatar
      fix comment · cf583f13
      Tudor Bosman authored
      Test Plan: No
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D709795
      cf583f13
    • Rajat Goel's avatar
      value_ might be uninitialized · 3cc8d95a
      Rajat Goel authored
      Summary: Compilation is failing in 'opt' build
      
      Test Plan: compile
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D707869
      3cc8d95a
    • Tudor Bosman's avatar
      Define ALLOCM_LG_ALIGN · 5fabcaa4
      Tudor Bosman authored
      Test Plan: No
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D707792
      5fabcaa4
    • Gaurav Jain's avatar
      Minor clang compiler fixes · 267e38a8
      Gaurav Jain authored
      Summary: Minor clang compiler fixes
      
      Test Plan: - fbmake runtest
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D707663
      267e38a8
    • Sergey Doroshenko's avatar
      Make AsyncIO::capacity_ const · bae2dccf
      Sergey Doroshenko authored
      Summary: It is set once, and is never changed afterwards.
      
      Test Plan: compiled, unit tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D706125
      bae2dccf
    • Jordan DeLong's avatar
      Codemod time\(NULL\) to time(nullptr) · a449e4aa
      Jordan DeLong authored
      Summary: codemod with 'Yes to all'.
      
      Test Plan: None really.
      
      Reviewed By: abirchall@fb.com
      
      FB internal diff: D693769
      a449e4aa
    • Tudor Bosman's avatar
      Fix subtle double-free in trimEnd; optionally pack IOBufQueue after append · 794e35e5
      Tudor Bosman authored
      Test Plan: folly/io/test, both dbg and opt, standalone and in valgrind
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D702755
      794e35e5
    • Tom Jackson's avatar
      all(), better any() · 0e21224b
      Tom Jackson authored
      Summary: TSIA
      
      Test Plan: Unit tests
      
      Reviewed By: tulloch@fb.com
      
      FB internal diff: D701890
      0e21224b
    • Tudor Bosman's avatar
      fix typos · 04223d27
      Tudor Bosman authored
      Test Plan: async_io_test
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D699175
      04223d27
    • Peter Griess's avatar
      Add some CursorBase::operator-() implementations · 9547cef8
      Peter Griess authored
      Summary:
      - Add CursorBase::operator-() implementations for Cursor and BufType;
      useful for figuring out the distance between two objects
      
      Test Plan: - Used in some other code
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D690046
      9547cef8