/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
== 2
>::type
addBenchmark(const char* file, const char* name, Lambda&& lambda) {
- auto execute = [=](unsigned int times) {
+ auto execute = [=](unsigned int times) -> uint64_t {
BenchmarkSuspender::nsSpent = 0;
timespec start, end;
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
template <class Uint>
size_t uintToHex(char* buffer, size_t bufLen, Uint v,
const char (&repr)[256][2]) {
- for (; v >= 256; v >>= 8) {
+ // 'v >>= 7, v >>= 1' is no more than a work around to get rid of shift size
+ // warning when Uint = uint8_t (it's false as v >= 256 implies sizeof(v) > 1).
+ for (; v >= 256; v >>= 7, v >>= 1) {
auto b = v & 0xff;
bufLen -= 2;
buffer[bufLen] = repr[b][0];
template <class Uint>
size_t uintToOctal(char* buffer, size_t bufLen, Uint v) {
auto& repr = formatOctal;
- for (; v >= 512; v >>= 9) {
+ // 'v >>= 7, v >>= 2' is no more than a work around to get rid of shift size
+ // warning when Uint = uint8_t (it's false as v >= 512 implies sizeof(v) > 1).
+ for (; v >= 512; v >>= 7, v >>= 2) {
auto b = v & 0x1ff;
bufLen -= 3;
buffer[bufLen] = repr[b][0];
buffer[--bufLen] = '0';
return bufLen;
}
- for (; v; v >>= 8) {
+ for (; v; v >>= 7, v >>= 1) {
auto b = v & 0xff;
bufLen -= 8;
memcpy(buffer + bufLen, &(repr[b][0]), 8);
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <cassert>
#include <cstdint>
+#include <cstring>
#include <functional>
#include <iterator>
#include <limits>
}
namespace {
-void setNonBlocking(int fd) {
- int flags = ::fcntl(fd, F_GETFL);
- checkUnixError(flags, "fcntl");
- int r = ::fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- checkUnixError(r, "fcntl");
-}
std::pair<const uint8_t*, size_t> queueFront(const IOBufQueue& queue) {
auto* p = queue.front();
IOBufQueue data) {
std::pair<IOBufQueue, IOBufQueue> out;
- auto readCallback = [&] (int pfd, int cfd) {
+ auto readCallback = [&] (int pfd, int cfd) -> bool {
if (cfd == 1 && flags.readStdout_) {
return handleRead(pfd, out.first);
} else if (cfd == 2 && flags.readStderr_) {
}
};
- auto writeCallback = [&] (int pfd, int cfd) {
+ auto writeCallback = [&] (int pfd, int cfd) -> bool {
if (cfd == 0 && flags.writeStdin_) {
return handleWrite(pfd, data);
} else {
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
template<class Body>
void foreach(Body&& body) const {
- this->self().apply([&](Value value) {
+ this->self().apply([&](Value value) -> bool {
body(std::forward<Value>(value));
return true;
});
public GenImpl<Result, Generator<Value, Source, Result>> {
Source source_;
Predicate pred_;
- public:
+ public:
explicit Generator(Source source, const Predicate& pred)
: source_(std::move(source)), pred_(pred) {}
*/
class Take : public Operator<Take> {
size_t count_;
-public:
+ public:
explicit Take(size_t count)
: count_(count) {}
*/
class Skip : public Operator<Skip> {
size_t count_;
-public:
+ public:
explicit Skip(size_t count)
: count_(count) {}
public GenImpl<Value, Generator<Value, Source>> {
Source source_;
size_t count_;
- public:
+ public:
explicit Generator(Source source, size_t count)
: source_(std::move(source)) , count_(count) {}
Selector selector_;
Comparer comparer_;
public:
- Order(const Selector& selector = Selector(),
- const Comparer& comparer = Comparer())
+ explicit Order(const Selector& selector = Selector(),
+ const Comparer& comparer = Comparer())
: selector_(selector) , comparer_(comparer) {}
template<class Value,
class Composed : public Operator<Composed<First, Second>> {
First first_;
Second second_;
- public:
- Composed() {}
- Composed(First first, Second second)
- : first_(std::move(first))
- , second_(std::move(second)) {}
+ public:
+ Composed() {}
+ Composed(First first, Second second)
+ : first_(std::move(first))
+ , second_(std::move(second)) {}
template<class Source,
class Value,
*/
class First : public Operator<First> {
public:
+ First() { }
+
template<class Source,
class Value,
class StorageType = typename std::decay<Value>::type>
*/
class Any : public Operator<Any> {
public:
+ Any() { }
+
template<class Source,
class Value>
bool compose(const GenImpl<Value, Source>& source) const {
class Reduce : public Operator<Reduce<Reducer>> {
Reducer reducer_;
public:
- Reduce(const Reducer& reducer)
+ explicit Reduce(const Reducer& reducer)
: reducer_(reducer)
{}
*/
class Count : public Operator<Count> {
public:
+ Count() { }
+
template<class Source,
class Value>
size_t compose(const GenImpl<Value, Source>& source) const {
*/
class Sum : public Operator<Sum> {
public:
+ Sum() { }
+
template<class Source,
class Value,
class StorageType = typename std::decay<Value>::type>
Selector selector_;
Comparer comparer_;
public:
- Min(const Selector& selector = Selector(),
- const Comparer& comparer = Comparer())
+ explicit Min(const Selector& selector = Selector(),
+ const Comparer& comparer = Comparer())
: selector_(selector)
, comparer_(comparer)
{}
template<class Collection>
class Collect : public Operator<Collect<Collection>> {
public:
+ Collect() { }
+
template<class Value,
class Source,
class StorageType = typename std::decay<Value>::type>
template<class> class Allocator>
class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
public:
+ CollectTemplate() { }
+
template<class Value,
class Source,
class StorageType = typename std::decay<Value>::type,
return collection;
}
};
+
/**
* Concat - For flattening generators of generators.
*
* | as<std::set>();
*/
class Concat : public Operator<Concat> {
-public:
+ public:
+ Concat() { }
+
template<class Inner,
class Source,
class InnerValue = typename std::decay<Inner>::type::ValueType>
class Generator :
public GenImpl<InnerValue, Generator<Inner, Source, InnerValue>> {
Source source_;
- public:
+ public:
explicit Generator(Source source)
: source_(std::move(source)) {}
* | as<std::set>();
*/
class RangeConcat : public Operator<RangeConcat> {
-public:
+ public:
+ RangeConcat() { }
+
template<class Source,
class Range,
class InnerValue = typename ValueTypeOfRange<Range>::RefType>
template<class Handler>
bool apply(Handler&& handler) const {
- return source_.apply([&](Range range) {
+ return source_.apply([&](Range range) -> bool {
for (auto& value : range) {
if (!handler(value)) {
return false;
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
EXPECT_EQ("42 23 hello worldXX", s);
}
-namespace {
-void testFloat(const char* fmt, double val) {
- char buf[100];
- sprintf(buf, to<std::string>("%", fmt).c_str(), val);
-
- EXPECT_EQ(buf, fstr(to<std::string>("{:", fmt, "}"), val));
-}
-} // namespace
-
TEST(Format, Float) {
double d = 1;
EXPECT_EQ("1", fstr("{}", 1.0));
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include "folly/stats/BucketedTimeSeries.h"
#include "folly/stats/BucketedTimeSeries-defs.h"
vector<BucketInfo> info;
auto fn = [&](const Bucket& bucket, seconds bucketStart,
- seconds bucketEnd) {
+ seconds bucketEnd) -> bool {
info.emplace_back(&bucket, bucketStart, bucketEnd);
return true;
};