<commit_before>/* 
 * File:   Buffer.cpp
 * Author: cjg
 * 
 * Created on October 18, 2009, 1:16 PM
 */

#include <cstring>
#include "Buffer.h"

using namespace std;

Buffer::Buffer(size_t initial_size, size_t block_size) {
    mSize = initial_size;
    mBlockSize = block_size;
    mLength = 0;
    mOffset = 0;
    mpBuffer = NULL;
    if (mSize == 0)
        mSize = 0;
    if ((mSize = (mSize / mBlockSize) * mBlockSize) == 0)
        mSize = mBlockSize;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    mBackOffset = mLength;
}

Buffer::Buffer(const Buffer& orig) {
    mBlockSize = orig.mBlockSize;
    mLength = orig.mLength;
    mSize = orig.mSize;
    mOffset = orig.mOffset;
    mLength = orig.mLength;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    memmove(mpBuffer, orig.mpBuffer, mLength);
    mBackOffset = mLength;
}

Buffer::Buffer(istream & in) {
    in.read((char *) &mSize, sizeof(size_t));
    mBlockSize = BLOCK_SIZE;
    mLength = mSize;
    mOffset = 0;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    in.read(mpBuffer, mSize);
    mBackOffset = mLength;
}

Buffer::Buffer(char* buffer, size_t buffer_size, size_t block_size) {
    mSize = buffer_size;
    mBlockSize = block_size;
    mLength = mSize;
    mOffset = 0;
    mpBuffer = buffer;
    mBackOffset = mLength;
}

Buffer::~Buffer() {
    /* FIXME: free the buffer */
    //free(mpBuffer);
}

void Buffer::Reset() {
    mLength = 0;
    mOffset = 0;
    mBackOffset = 0;
}
<commit_msg>saving some byte while copying buffer<commit_after>/* 
 * File:   Buffer.cpp
 * Author: cjg
 * 
 * Created on October 18, 2009, 1:16 PM
 */

#include <cstring>
#include "Buffer.h"

using namespace std;

Buffer::Buffer(size_t initial_size, size_t block_size) {
    mSize = initial_size;
    mBlockSize = block_size;
    mLength = 0;
    mOffset = 0;
    mpBuffer = NULL;
    if (mSize == 0)
        mSize = 0;
    if ((mSize = (mSize / mBlockSize) * mBlockSize) == 0)
        mSize = mBlockSize;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    mBackOffset = mLength;
}

Buffer::Buffer(const Buffer& orig) {
    mBlockSize = orig.mBlockSize;
    mLength = orig.mLength;
    mSize = orig.mLength;
    mOffset = orig.mOffset;
    mLength = orig.mLength;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    memmove(mpBuffer, orig.mpBuffer, mLength);
    mBackOffset = mLength;
}

Buffer::Buffer(istream & in) {
    in.read((char *) &mSize, sizeof(size_t));
    mBlockSize = BLOCK_SIZE;
    mLength = mSize;
    mOffset = 0;
    if ((mpBuffer = (char *) malloc(mSize)) == NULL)
        throw "Can't allocate memory.";
    in.read(mpBuffer, mSize);
    mBackOffset = mLength;
    cout << "Buffer " << mSize << " " << mLength << " " << mOffset << " "
        << mBackOffset << endl;
}

Buffer::Buffer(char* buffer, size_t buffer_size, size_t block_size) {
    mSize = buffer_size;
    mBlockSize = block_size;
    mLength = mSize;
    mOffset = 0;
    mpBuffer = buffer;
    mBackOffset = mLength;
}

Buffer::~Buffer() {
    /* FIXME: free the buffer */
    //free(mpBuffer);
}

void Buffer::Reset() {
    mLength = 0;
    mOffset = 0;
    mBackOffset = 0;
}

{'fraction_non_alphanumeric': 0.14204883859440143, 'fraction_numerical': 0.011316259678379988, 'mean_word_length': 2.821387940841866, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '161232', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1181, 'n_words': 292}