Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::StringBuffer Class Reference

#include <string-buffer.h>

Collaboration diagram for impala::StringBuffer:

Public Member Functions

 StringBuffer (MemPool *pool, StringValue *str=NULL)
 
void Append (const char *str, int len)
 Append 'str' to the current string, allocating a new buffer as necessary. More...
 
void Append (const uint8_t *str, int len)
 TODO: switch everything to uint8_t? More...
 
void Assign (const char *str, int len)
 Assigns contents to StringBuffer. More...
 
void Clear ()
 Clear the underlying StringValue. The allocated buffer can be reused. More...
 
void Reset ()
 Clears the underlying buffer and StringValue. More...
 
bool Empty () const
 Returns whether the current string is empty. More...
 
int Size () const
 Returns the length of the current string. More...
 
const StringValuestr () const
 Returns the underlying StringValue. More...
 
int buffer_size () const
 Returns the buffer size. More...
 

Private Member Functions

void GrowBuffer (int new_len)
 

Private Attributes

MemPoolpool_
 
StringValue string_value_
 
int buffer_size_
 

Detailed Description

Dynamic-sizable string (similar to std::string) but without as many copies and allocations. StringBuffer wraps a StringValue object with a pool and memory buffer length. It supports a subset of the std::string functionality but will only allocate bigger string buffers as necessary. std::string tries to be immutable and will reallocate very often. std::string should be avoided in all hot paths.

Definition at line 30 of file string-buffer.h.

Constructor & Destructor Documentation

impala::StringBuffer::StringBuffer ( MemPool pool,
StringValue str = NULL 
)
inline

C'tor for StringBuffer. Memory backing the string will be allocated from the pool as necessary. Can optionally be initialized from a StringValue.

Definition at line 34 of file string-buffer.h.

References buffer_size_, impala::StringValue::len, pool_, str(), and string_value_.

Member Function Documentation

void impala::StringBuffer::Append ( const char *  str,
int  len 
)
inline

Append 'str' to the current string, allocating a new buffer as necessary.

Definition at line 44 of file string-buffer.h.

References buffer_size_, GrowBuffer(), impala::StringValue::len, impala::StringValue::ptr, and string_value_.

Referenced by Append(), Assign(), impala::HdfsTextScanner::ProcessRange(), and impala::TEST().

void impala::StringBuffer::Append ( const uint8_t *  str,
int  len 
)
inline

TODO: switch everything to uint8_t?

Definition at line 54 of file string-buffer.h.

References Append().

void impala::StringBuffer::Assign ( const char *  str,
int  len 
)
inline

Assigns contents to StringBuffer.

Definition at line 59 of file string-buffer.h.

References Append(), and Clear().

Referenced by impala::TEST().

int impala::StringBuffer::buffer_size ( ) const
inline

Returns the buffer size.

Definition at line 91 of file string-buffer.h.

References buffer_size_.

Referenced by impala::TEST().

void impala::StringBuffer::Clear ( )
inline

Clear the underlying StringValue. The allocated buffer can be reused.

Definition at line 65 of file string-buffer.h.

References impala::StringValue::len, and string_value_.

Referenced by Assign(), impala::HdfsTextScanner::ProcessRange(), impala::HdfsTextScanner::ResetScanner(), impala::TEST(), and impala::HdfsTextScanner::WriteFields().

bool impala::StringBuffer::Empty ( ) const
inline
void impala::StringBuffer::GrowBuffer ( int  new_len)
inlineprivate

Grows the buffer backing the string to be at least new_size, copying over the previous string data into the new buffer.

Definition at line 98 of file string-buffer.h.

References impala::MemPool::Allocate(), buffer_size_, impala::StringValue::len, pool_, impala::StringValue::ptr, and string_value_.

Referenced by Append().

void impala::StringBuffer::Reset ( )
inline

Clears the underlying buffer and StringValue.

Definition at line 70 of file string-buffer.h.

References buffer_size_, impala::StringValue::len, and string_value_.

int impala::StringBuffer::Size ( ) const
inline

Returns the length of the current string.

Definition at line 81 of file string-buffer.h.

References impala::StringValue::len, and string_value_.

Referenced by impala::HdfsTextScanner::CopyBoundaryField(), impala::HdfsTextScanner::FinishScanRange(), and impala::ValidateString().

const StringValue& impala::StringBuffer::str ( ) const
inline

Member Data Documentation

int impala::StringBuffer::buffer_size_
private

Definition at line 110 of file string-buffer.h.

Referenced by Append(), buffer_size(), GrowBuffer(), Reset(), and StringBuffer().

MemPool* impala::StringBuffer::pool_
private

Definition at line 108 of file string-buffer.h.

Referenced by GrowBuffer(), and StringBuffer().

StringValue impala::StringBuffer::string_value_
private

Definition at line 109 of file string-buffer.h.

Referenced by Append(), Clear(), Empty(), GrowBuffer(), Reset(), Size(), str(), and StringBuffer().


The documentation for this class was generated from the following file: