[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings

Thiago Macieira thiago.macieira at intel.com
Wed Oct 14 18:11:26 CEST 2015


On Wednesday 14 October 2015 08:51:11 Thiago Macieira wrote:
> The separation of the string itself from the size and the d pointer allows
> the  compiler, if it wants to, to share strings. In fact, disassembly of
> 
>         f(QStringLiteral("foo"), QStringLiteral("foo")) 
> 
> produces one copy of u"foo" only.

Let me expand on this.

Current Qt5 QStringLiteral("foo") produces a data block of size
	sizeof(QArrayData) + sizeof(u"foo") = 24 + 8 = 32 bytes

and the fact that QStringLiterals don't share will cause the innocent-looking 
above code require 64 bytes of read-only data.

My current code expands to 8 bytes of read-only data, at the expense of a 
little more code.

Current code:

        leaq    _ZZZ1fvENKUlvE0_clEvE15qstring_literal(%rip), %rax
        movq    %rax, 16(%rsp)
        leaq    _ZZZ1fvENKUlvE_clEvE15qstring_literal(%rip), %rax
        movq    %rax, (%rsp)
	; followed by the call:
        movq    %rsp, %rdi
        leaq    16(%rsp), %rsi
        call    _Z1fRK7QStringS1_ at PLT

My code:

        leaq    .LC0(%rip), %rcx			; u"foo"
        movq    _ZN10QArrayData18shared_static_dataE at GOTPCREL(%rip), %rax
        movq    %rcx, 40(%rsp)
        movl    $3, 48(%rsp)
        movq    %rcx, 8(%rsp)
        movq    %rax, 32(%rsp)
        movq    %rax, (%rsp)
        movl    $3, 16(%rsp)
	; the call itself is unchanged:
        movq    %rsp, %rdi
        leaq    32(%rsp), %rsi
        call    _Z1fRK7QStringS1_ at PLT

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list