[Development] optimizing QComposeInputContext / TableGenerator?

Kevin Kofler kevin.kofler at chello.at
Tue Jan 20 04:32:21 CET 2015


Milian Wolff wrote:
> It can, indeed. But funnily enough it's not going to be much faster, at
> least in the tests I did. Still, one should probably be doing this
> anyways. I'll try to dig up my patch for that and sent it to Gerrit. It's
> a pity that one cannot just convert a const char* to a QChar directly,
> i.e. without any allocations. One cannot even reuse the same QString
> buffer to my knowledge...

Why not something like this?

QChar getQChar(const char *p)
{
  unsigned short uc = 0;
  char c = *(p++);
  if (c < -64) // invalid UTF-8
    uc = 0;
  else if (c < -32) { // 2 chars
    uc = ((unsigned short) (c & 31)) << 6;
    c = *(p++);
    if (c >= 0)
      uc = 0; // error (ASCII or end of string as continuation char)
    else
      uc |= (unsigned short) (c & 63);
  } else if (c < -16) { // 3 chars
    uc = ((unsigned short) (c & 15)) << 12;
    c = *(p++);
    if (c >= 0)
      uc = 0; // error (ASCII or end of string as continuation char)
    else {
      uc |= ((unsigned short) (c & 63)) << 6;
      c = *(p++);
      if (c >= 0)
        uc = 0; // error (ASCII or end of string as continuation char)
      else
        uc |= (unsigned short) (c & 63);
    }
  } else if (c < 0) // 4 chars, codepoint above 65536, would need 2 QChars
    uc = 0;
  else
    uc = c;
  return QChar(uc);
}

        Kevin Kofler




More information about the Development mailing list