Moving towards more flat buffering. Speed is still lower than the original Be implementation, but it's not because of the backend, it's probably the slow BMessage::Header implementation.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13909 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -43,16 +43,17 @@ public:
|
||||
status_t Flatten(BDataIO *stream) const;
|
||||
status_t Unflatten(BDataIO *stream);
|
||||
|
||||
status_t AddData(const char *name, BSimpleMallocIO *buffer,
|
||||
type_code type);
|
||||
status_t AddData(const char *name, type_code type,
|
||||
size_t length, void **buffer,
|
||||
bool fixedSize = false, int32 count = 1);
|
||||
status_t RemoveData(const char *name, int32 index = 0);
|
||||
|
||||
bool HasData(const char *name, type_code t, int32 n) const;
|
||||
status_t FindData(const char *name, type_code type,
|
||||
int32 index, const void **data,
|
||||
ssize_t *numBytes) const;
|
||||
status_t ReplaceData(const char *name, int32 index,
|
||||
BSimpleMallocIO *buffer, type_code type);
|
||||
status_t ReplaceData(const char *name, type_code type,
|
||||
int32 index, size_t length, void **buffer);
|
||||
|
||||
status_t Rename(const char *oldName, const char *newName);
|
||||
status_t RemoveName(const char *name);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#ifndef _MESSAGE_FIELD_H_
|
||||
#define _MESSAGE_FIELD_H_
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#define MSG_FLAG_VALID 0x01
|
||||
@@ -25,36 +25,47 @@
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class BSimpleMallocIO;
|
||||
typedef struct field_header_s {
|
||||
uint8 flags;
|
||||
type_code type;
|
||||
int32 count;
|
||||
ssize_t dataSize;
|
||||
uint8 nameLength;
|
||||
char name[255];
|
||||
} __attribute__((__packed__)) FieldHeader;
|
||||
|
||||
class BMessageField {
|
||||
public:
|
||||
BMessageField();
|
||||
BMessageField(const char *name, type_code type);
|
||||
BMessageField(uint8 flags, BDataIO *stream);
|
||||
BMessageField(const BMessageField &other);
|
||||
~BMessageField();
|
||||
|
||||
BMessageField &operator=(const BMessageField &other);
|
||||
|
||||
uint8 Flags();
|
||||
void Flatten(BDataIO *stream);
|
||||
void Unflatten(uint8 flags, BDataIO *stream);
|
||||
|
||||
uint8 Flags() { return fHeader.flags; };
|
||||
|
||||
void SetName(const char *name);
|
||||
const char *Name() const { return fName.String(); };
|
||||
uint8 NameLength() const { return fName.Length(); };
|
||||
type_code Type() const { return fType; };
|
||||
const char *Name() const { return fHeader.name; };
|
||||
uint8 NameLength() const { return fHeader.nameLength; };
|
||||
type_code Type() const { return fHeader.type; };
|
||||
|
||||
void AddItem(BSimpleMallocIO *item);
|
||||
void ReplaceItem(int32 index, BSimpleMallocIO *item);
|
||||
void *AddItem(size_t length);
|
||||
void *ReplaceItem(int32 index, size_t newLength);
|
||||
void RemoveItem(int32 index);
|
||||
int32 CountItems() const { return fItems.CountItems(); };
|
||||
size_t SizeAt(int32 index) const;
|
||||
const void *BufferAt(int32 index) const;
|
||||
int32 CountItems() const { return fHeader.count; };
|
||||
|
||||
const void *BufferAt(int32 index, ssize_t *size) const;
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
bool IsFixedSize() const { return fFixedSize; };
|
||||
size_t TotalSize() const { return fTotalSize; };
|
||||
size_t TotalPadding() const { return fTotalPadding; };
|
||||
status_t SetFixedSize(int32 itemSize, int32 count);
|
||||
bool IsFixedSize() const { return fHeader.flags & MSG_FLAG_FIXED_SIZE; };
|
||||
size_t TotalSize() const { return fHeader.dataSize; };
|
||||
|
||||
void PrintToStream() const;
|
||||
|
||||
@@ -63,15 +74,20 @@ public:
|
||||
BMessageField *Next() const { return fNext; };
|
||||
|
||||
private:
|
||||
bool IsFixedSize(type_code type);
|
||||
void ResetHeader(const char *name, type_code type);
|
||||
void FlatResize(int32 offset, size_t oldLength,
|
||||
size_t newLength);
|
||||
|
||||
BString fName;
|
||||
type_code fType;
|
||||
BList fItems;
|
||||
bool fFixedSize;
|
||||
size_t fTotalSize;
|
||||
size_t fTotalPadding;
|
||||
FieldHeader fHeader;
|
||||
mutable BMallocIO fFlatBuffer;
|
||||
|
||||
// fixed size items
|
||||
int32 fItemSize;
|
||||
|
||||
// variable sized items
|
||||
BList *fOffsets;
|
||||
|
||||
// hash table support
|
||||
BMessageField *fNext;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user