Skip to content

Commit

Permalink
Fully qualify std::string.
Browse files Browse the repository at this point in the history
This is in preparation for removing the snappy::string alias
of std::string.

PiperOrigin-RevId: 271383199
  • Loading branch information
pwnall committed Sep 26, 2019
1 parent d837d5c commit 62363d9
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 118 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion snappy-stubs-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace snappy {

void Varint::Append32(string* s, uint32 value) {
void Varint::Append32(std::string* s, uint32 value) {
char buf[Varint::kMax32];
const char* p = Varint::Encode32(buf, value);
s->append(buf, p - buf);
Expand Down
6 changes: 3 additions & 3 deletions snappy-stubs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class Varint {
static char* Encode32(char* ptr, uint32 v);

// EFFECTS Appends the varint representation of "value" to "*s".
static void Append32(string* s, uint32 value);
static void Append32(std::string* s, uint32 value);
};

inline const char* Varint::Parse32WithLimit(const char* p,
Expand Down Expand Up @@ -581,7 +581,7 @@ inline char* Varint::Encode32(char* sptr, uint32 v) {
// replace this function with one that resizes the string without
// filling the new space with zeros (if applicable) --
// it will be non-portable but faster.
inline void STLStringResizeUninitialized(string* s, size_t new_size) {
inline void STLStringResizeUninitialized(std::string* s, size_t new_size) {
s->resize(new_size);
}

Expand All @@ -597,7 +597,7 @@ inline void STLStringResizeUninitialized(string* s, size_t new_size) {
// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#530)
// proposes this as the method. It will officially be part of the standard
// for C++0x. This should already work on all current implementations.
inline char* string_as_array(string* str) {
inline char* string_as_array(std::string* str) {
return str->empty() ? NULL : &*str->begin();
}

Expand Down
22 changes: 11 additions & 11 deletions snappy-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ DEFINE_bool(run_microbenchmarks, true,

namespace snappy {

string ReadTestDataFile(const string& base, size_t size_limit) {
string contents;
std::string ReadTestDataFile(const std::string& base, size_t size_limit) {
std::string contents;
const char* srcdir = getenv("srcdir"); // This is set by Automake.
string prefix;
std::string prefix;
if (srcdir) {
prefix = string(srcdir) + "/";
prefix = std::string(srcdir) + "/";
}
file::GetContents(prefix + "testdata/" + base, &contents, file::Defaults()
).CheckSuccess();
Expand All @@ -63,11 +63,11 @@ string ReadTestDataFile(const string& base, size_t size_limit) {
return contents;
}

string ReadTestDataFile(const string& base) {
std::string ReadTestDataFile(const std::string& base) {
return ReadTestDataFile(base, 0);
}

string StringPrintf(const char* format, ...) {
std::string StringPrintf(const char* format, ...) {
char buf[4096];
va_list ap;
va_start(ap, format);
Expand All @@ -79,7 +79,7 @@ string StringPrintf(const char* format, ...) {
bool benchmark_running = false;
int64 benchmark_real_time_us = 0;
int64 benchmark_cpu_time_us = 0;
string *benchmark_label = NULL;
std::string* benchmark_label = nullptr;
int64 benchmark_bytes_processed = 0;

void ResetBenchmarkTiming() {
Expand Down Expand Up @@ -163,11 +163,11 @@ void StopBenchmarkTiming() {
benchmark_running = false;
}

void SetBenchmarkLabel(const string& str) {
void SetBenchmarkLabel(const std::string& str) {
if (benchmark_label) {
delete benchmark_label;
}
benchmark_label = new string(str);
benchmark_label = new std::string(str);
}

void SetBenchmarkBytesProcessed(int64 bytes) {
Expand Down Expand Up @@ -217,8 +217,8 @@ void Benchmark::Run() {
benchmark_runs[run].cpu_time_us = benchmark_cpu_time_us;
}

string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
string human_readable_speed;
std::string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
std::string human_readable_speed;

std::nth_element(benchmark_runs,
benchmark_runs + kMedianPos,
Expand Down
16 changes: 8 additions & 8 deletions snappy-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace file {
namespace snappy {

#define FLAGS_test_random_seed 301
typedef string TypeParam;
using TypeParam = std::string;

void Test_CorruptedTest_VerifyCorrupted();
void Test_Snappy_SimpleTests();
Expand All @@ -181,13 +181,13 @@ void Test_Snappy_ReadPastEndOfBuffer();
void Test_Snappy_FindMatchLength();
void Test_Snappy_FindMatchLengthRandom();

string ReadTestDataFile(const string& base, size_t size_limit);
std::string ReadTestDataFile(const std::string& base, size_t size_limit);

string ReadTestDataFile(const string& base);
std::string ReadTestDataFile(const std::string& base);

// A sprintf() variant that returns a std::string.
// Not safe for general use due to truncation issues.
string StringPrintf(const char* format, ...);
std::string StringPrintf(const char* format, ...);

// A wall-time clock. This stub is not super-accurate, nor resistant to the
// system time changing.
Expand Down Expand Up @@ -241,8 +241,8 @@ typedef void (*BenchmarkFunction)(int, int);

class Benchmark {
public:
Benchmark(const string& name, BenchmarkFunction function) :
name_(name), function_(function) {}
Benchmark(const std::string& name, BenchmarkFunction function)
: name_(name), function_(function) {}

Benchmark* DenseRange(int start, int stop) {
start_ = start;
Expand All @@ -253,7 +253,7 @@ class Benchmark {
void Run();

private:
const string name_;
const std::string name_;
const BenchmarkFunction function_;
int start_, stop_;
};
Expand All @@ -271,7 +271,7 @@ extern Benchmark* Benchmark_BM_ZFlatIncreasingTableSize;
void ResetBenchmarkTiming();
void StartBenchmarkTiming();
void StopBenchmarkTiming();
void SetBenchmarkLabel(const string& str);
void SetBenchmarkLabel(const std::string& str);
void SetBenchmarkBytesProcessed(int64 bytes);

#ifdef HAVE_LIBZ
Expand Down
5 changes: 3 additions & 2 deletions snappy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ bool RawUncompress(Source* compressed, char* uncompressed) {
return InternalUncompress(compressed, &output);
}

bool Uncompress(const char* compressed, size_t n, string* uncompressed) {
bool Uncompress(const char* compressed, size_t n, std::string* uncompressed) {
size_t ulength;
if (!GetUncompressedLength(compressed, n, &ulength)) {
return false;
Expand Down Expand Up @@ -1414,7 +1414,8 @@ void RawCompress(const char* input,
*compressed_length = (writer.CurrentDestination() - compressed);
}

size_t Compress(const char* input, size_t input_length, string* compressed) {
size_t Compress(const char* input, size_t input_length,
std::string* compressed) {
// Pre-grow the buffer to the max length of the compressed output
STLStringResizeUninitialized(compressed, MaxCompressedLength(input_length));

Expand Down
11 changes: 6 additions & 5 deletions snappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ namespace snappy {
// Higher-level string based routines (should be sufficient for most users)
// ------------------------------------------------------------------------

// Sets "*output" to the compressed version of "input[0,input_length-1]".
// Original contents of *output are lost.
// Sets "*compressed" to the compressed version of "input[0,input_length-1]".
// Original contents of *compressed are lost.
//
// REQUIRES: "input[]" is not an alias of "*output".
size_t Compress(const char* input, size_t input_length, string* output);
// REQUIRES: "input[]" is not an alias of "*compressed".
size_t Compress(const char* input, size_t input_length,
std::string* compressed);

// Decompresses "compressed[0,compressed_length-1]" to "*uncompressed".
// Original contents of "*uncompressed" are lost.
Expand All @@ -82,7 +83,7 @@ namespace snappy {
//
// returns false if the message is corrupted and could not be decompressed
bool Uncompress(const char* compressed, size_t compressed_length,
string* uncompressed);
std::string* uncompressed);

// Decompresses "compressed" to "*uncompressed".
//
Expand Down
Loading

0 comments on commit 62363d9

Please sign in to comment.