On 10/17/11 1:10 PM, "ext Thiago Macieira" <[email protected]> wrote:
>Let's call this one option 0:
>
>> > Here's an idea:
>> > QAtomicInt ref;
>> > int alloc;
>> > union {
>> >
>> > qptrdiff offset;
>> > struct { int begin; int end; };
>> >
>> > };
>> > // size = 16 bytes
>
>> Option 1:
>>
>> QAtomicInt ref;
>> int alloc;
>> union {
>> qptrdiff begin;
>> qint64 dummy;
>> };
>> int end;
>> int flags;
>> // size = 24 bytes
>
>> Option 2:
>>
>> QAtomicInt ref;
>> int flags;
>> union {
>> qptrdiff alloc;
>> qint64 dummy;
>> };
>> qptrdiff begin;
>> qptrdiff end;
>> // size = 24 (32) bytes
>
>Here's another suggestion now, with "split personality". It's not very
>good,
>so suggestions to improve are very much welcome.
>
>Option 3:
>struct QArrayData {
> QAtomicInt ref;
> int begin;
> int size;
> int flags;
> // size = 16 bytes
>};
>
>struct QArrayRawData {
> T *offset;
> void (*deleterFunction)(T *);
>};
>
>struct QArrayOwnData {
> int alloc;
> int hash;
> ...
>};
>
>Somewhere in the fixed header, we need an indication of whether the data
>is raw
>or allocated by us. It can be either a bit in the flags or a negative
>begin
>value (begin is unused if offset is used). I replaced the end value with
>size,
>which means the number of elements allocated but unused past the end is:
> alloc - begin - size
>
>However, the calculation of the beginning of the data pointer now
>involves a
>comparison:
> T *data()
> {
> if (d->isRawData()) return d->rawData()->offset;
> return d->array() + d->begin;
> }
Aren't we now making things way to complicated?
If we go for storing the hash in the string as well, we can't do it in 16
bytes, so 24 is our next best option on 32bit systems. How about a simple
struct Data {
QRefCount ref;
int alloc;
uint32 flags;
uint32 hash;
int size; // or end, depending on what's more convenient
qptrdiff begin;
}
This gives 24 bytes on 32bit systems, 32 on 64bit. The hash stays 0 for
compile time strings.
Another option we discussed earlier (at least for QString and QByteArray
was to remove the fromRawData() functionality. In that case we could
simply do:
struct QString/ByteArrayData {
QRefCount ref;
int alloc;
int size; // or end, depending on what's more convenient
uint32 hash;
}
and try to squeeze the required bits into the sign bits of alloc and size.
Cheers,
Lars
_______________________________________________
Qt5-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback