summaryrefslogtreecommitdiff
path: root/port
diff options
context:
space:
mode:
authorgabor@google.com <gabor@google.com@62dab493-f737-651d-591e-8d6aee1b9529>2011-07-21 02:40:18 +0000
committergabor@google.com <gabor@google.com@62dab493-f737-651d-591e-8d6aee1b9529>2011-07-21 02:40:18 +0000
commit60bd8015f21fdb63d5409b1191f8ea9d8f1a1b87 (patch)
treedab21fd0d1309be4e6851f690e1c011e79ddbf6b /port
parent6872ace90110799f87402cbc594c4cbf1bc474c7 (diff)
downloadleveldb-60bd8015f21fdb63d5409b1191f8ea9d8f1a1b87.tar.gz
Speed up Snappy uncompression, new Logger interface.
- 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
Diffstat (limited to 'port')
-rw-r--r--port/atomic_pointer.h14
-rw-r--r--port/port_android.h8
-rw-r--r--port/port_chromium.cc18
-rw-r--r--port/port_chromium.h4
-rw-r--r--port/port_example.h12
-rw-r--r--port/port_posix.h26
6 files changed, 58 insertions, 24 deletions
diff --git a/port/atomic_pointer.h b/port/atomic_pointer.h
index c618778..c20b1bd 100644
--- a/port/atomic_pointer.h
+++ b/port/atomic_pointer.h
@@ -48,9 +48,8 @@ namespace port {
// http://msdn.microsoft.com/en-us/library/ms684208(v=vs.85).aspx
#define LEVELDB_HAVE_MEMORY_BARRIER
-// Gcc and Sun Studio on x86
-#elif defined(ARCH_CPU_X86_FAMILY) && \
- (defined(__GNUC__) || defined(__SUNPRO_CC))
+// Gcc on x86
+#elif defined(ARCH_CPU_X86_FAMILY) && defined(__GNUC__)
inline void MemoryBarrier() {
// See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
// this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
@@ -58,6 +57,15 @@ inline void MemoryBarrier() {
}
#define LEVELDB_HAVE_MEMORY_BARRIER
+// Sun Studio
+#elif defined(ARCH_CPU_X86_FAMILY) && defined(__SUNPRO_CC)
+inline void MemoryBarrier() {
+ // See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
+ // this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
+ asm volatile("" : : : "memory");
+}
+#define LEVELDB_HAVE_MEMORY_BARRIER
+
// Mac OS
#elif defined(OS_MACOSX)
inline void MemoryBarrier() {
diff --git a/port/port_android.h b/port/port_android.h
index 13df9c9..d68b6c0 100644
--- a/port/port_android.h
+++ b/port/port_android.h
@@ -126,10 +126,16 @@ inline bool Snappy_Compress(
}
// TODO(gabor): Implement uncompress
+inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
+ size_t* result) {
+ return false;
+}
+
+// TODO(gabor): Implement uncompress
inline bool Snappy_Uncompress(
const char* input_data,
size_t input_length,
- std::string* output) {
+ char* output) {
return false;
}
diff --git a/port/port_chromium.cc b/port/port_chromium.cc
index 2ab49b9..7f6de92 100644
--- a/port/port_chromium.cc
+++ b/port/port_chromium.cc
@@ -62,15 +62,19 @@ bool Snappy_Compress(const char* input, size_t input_length,
#endif
}
+bool Snappy_GetUncompressedLength(const char* input, size_t length,
+ size_t* result) {
+#if defined(USE_SNAPPY)
+ return snappy::GetUncompressedLength(input_data, input_length, result);
+#else
+ return false;
+#endif
+}
+
bool Snappy_Uncompress(const char* input_data, size_t input_length,
- std::string* output) {
+ char* output) {
#if defined(USE_SNAPPY)
- size_t ulength;
- if (!snappy::GetUncompressedLength(input_data, input_length, &ulength)) {
- return false;
- }
- output->resize(ulength);
- return snappy::RawUncompress(input_data, input_length, &(*output)[0]);
+ return snappy::RawUncompress(input_data, input_length, output);
#else
return false;
#endif
diff --git a/port/port_chromium.h b/port/port_chromium.h
index 1851e6e..feecd5b 100644
--- a/port/port_chromium.h
+++ b/port/port_chromium.h
@@ -84,8 +84,10 @@ class AtomicPointer {
bool Snappy_Compress(const char* input, size_t input_length,
std::string* output);
+bool Snappy_GetUncompressedLength(const char* input, size_t length,
+ size_t* result);
bool Snappy_Uncompress(const char* input_data, size_t input_length,
- std::string* output);
+ char* output);
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
return false;
diff --git a/port/port_example.h b/port/port_example.h
index 8a624f3..6bd9b49 100644
--- a/port/port_example.h
+++ b/port/port_example.h
@@ -96,11 +96,21 @@ class AtomicPointer {
extern bool Snappy_Compress(const char* input, size_t input_length,
std::string* output);
+// If input[0,input_length-1] looks like a valid snappy compressed
+// buffer, store the size of the uncompressed data in *result and
+// return true. Else return false.
+extern bool Snappy_GetUncompressedLength(const char* input, size_t length,
+ size_t* result);
+
// Attempt to snappy uncompress input[0,input_length-1] into *output.
// Returns true if successful, false if the input is invalid lightweight
// compressed data.
+//
+// REQUIRES: at least the first "n" bytes of output[] must be writable
+// where "n" is the result of a successful call to
+// Snappy_GetUncompressedLength.
extern bool Snappy_Uncompress(const char* input_data, size_t input_length,
- std::string* output);
+ char* output);
// ------------------ Miscellaneous -------------------
diff --git a/port/port_posix.h b/port/port_posix.h
index 2995026..ef01de3 100644
--- a/port/port_posix.h
+++ b/port/port_posix.h
@@ -80,12 +80,12 @@ class CondVar {
Mutex* mu_;
};
-inline bool Snappy_Compress(const char* input, size_t input_length,
+inline bool Snappy_Compress(const char* input, size_t length,
::std::string* output) {
#ifdef SNAPPY
- output->resize(snappy::MaxCompressedLength(input_length));
+ output->resize(snappy::MaxCompressedLength(length));
size_t outlen;
- snappy::RawCompress(input, input_length, &(*output)[0], &outlen);
+ snappy::RawCompress(input, length, &(*output)[0], &outlen);
output->resize(outlen);
return true;
#endif
@@ -93,18 +93,22 @@ inline bool Snappy_Compress(const char* input, size_t input_length,
return false;
}
-inline bool Snappy_Uncompress(const char* input_data, size_t input_length,
- ::std::string* output) {
+inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
+ size_t* result) {
#ifdef SNAPPY
- size_t ulength;
- if (!snappy::GetUncompressedLength(input_data, input_length, &ulength)) {
- return false;
- }
- output->resize(ulength);
- return snappy::RawUncompress(input_data, input_length, &(*output)[0]);
+ return snappy::GetUncompressedLength(input, length, result);
+#else
+ return false;
#endif
+}
+inline bool Snappy_Uncompress(const char* input, size_t length,
+ char* output) {
+#ifdef SNAPPY
+ return snappy::RawUncompress(input, length, output);
+#else
return false;
+#endif
}
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {