60bd8015f2
- Removed one copy of an uncompressed block contents changing the signature of Snappy_Uncompress() so it uncompresses into a flat array instead of a std::string. Speeds up readrandom ~10%. - Instead of a combination of Env/WritableFile, we now have a Logger interface that can be easily overridden applications that want to supply their own logging. - Separated out the gcc and Sun Studio parts of atomic_pointer.h so we can use 'asm', 'volatile' keywords for Sun Studio. git-svn-id: https://leveldb.googlecode.com/svn/trunk@39 62dab493-f737-651d-591e-8d6aee1b9529
83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#include "leveldb/env.h"
|
|
|
|
namespace leveldb {
|
|
|
|
Env::~Env() {
|
|
}
|
|
|
|
SequentialFile::~SequentialFile() {
|
|
}
|
|
|
|
RandomAccessFile::~RandomAccessFile() {
|
|
}
|
|
|
|
WritableFile::~WritableFile() {
|
|
}
|
|
|
|
Logger::~Logger() {
|
|
}
|
|
|
|
FileLock::~FileLock() {
|
|
}
|
|
|
|
void Log(Logger* info_log, const char* format, ...) {
|
|
if (info_log != NULL) {
|
|
va_list ap;
|
|
va_start(ap, format);
|
|
info_log->Logv(format, ap);
|
|
va_end(ap);
|
|
}
|
|
}
|
|
|
|
Status WriteStringToFile(Env* env, const Slice& data,
|
|
const std::string& fname) {
|
|
WritableFile* file;
|
|
Status s = env->NewWritableFile(fname, &file);
|
|
if (!s.ok()) {
|
|
return s;
|
|
}
|
|
s = file->Append(data);
|
|
if (s.ok()) {
|
|
s = file->Close();
|
|
}
|
|
delete file; // Will auto-close if we did not close above
|
|
if (!s.ok()) {
|
|
env->DeleteFile(fname);
|
|
}
|
|
return s;
|
|
}
|
|
|
|
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
|
|
data->clear();
|
|
SequentialFile* file;
|
|
Status s = env->NewSequentialFile(fname, &file);
|
|
if (!s.ok()) {
|
|
return s;
|
|
}
|
|
static const int kBufferSize = 8192;
|
|
char* space = new char[kBufferSize];
|
|
while (true) {
|
|
Slice fragment;
|
|
s = file->Read(kBufferSize, &fragment, space);
|
|
if (!s.ok()) {
|
|
break;
|
|
}
|
|
data->append(fragment.data(), fragment.size());
|
|
if (fragment.empty()) {
|
|
break;
|
|
}
|
|
}
|
|
delete[] space;
|
|
delete file;
|
|
return s;
|
|
}
|
|
|
|
EnvWrapper::~EnvWrapper() {
|
|
}
|
|
|
|
}
|