C++ question: literal form of std::map<int, std::array>

Eike Rathke erack at redhat.com
Thu May 14 19:56:19 UTC 2020


Hi Naruhiko,

On Thursday, 2020-05-14 19:40:19 +0900, Naruhiko Ogasawara wrote:

> Now I'm trying to resolve tdf#130140 and tdf#130193, both of them
> relate to the mapping between NatNum of Calc and DBNum of Excel.

Great you're looking into that!

> static const std::map<LanguageType, std::vector<sal_uInt8>> tblDBNumToNatNum
>     = { { primary(LANGUAGE_CHINESE),    { 4, 5, 6, 0 } },
>         { primary(LANGUAGE_JAPANESE),   { 4, 5, 3, 0 } },
>         { primary(LANGUAGE_KOREAN),     { 1, 2, 3, 9 } } };
> [...]
>           if (tblDBNumToNatNum.count(eLang) != 0)
>         {
>             nNatNum = tblDBNumToNatNum.at(eLang)[nDBNum - 1];
>         }

Apart from the array vs vector problem, instead of counting the mapped
elements each time it would be more efficient to obtain a match (or
non-match) right away and use that, like (untested)

    auto const it = tblDBNumToNatNum.find(eLang);
    if (it != tblDBNumToNatNum.end())
        nNatNum = it->second[nDBNum - 1]

Also, as we have constant data here that isn't modified, using std::set
could be more appropriate than std::map.

  Eike

-- 
GPG key 0x6A6CD5B765632D3A - 2265 D7F3 A7B0 95CC 3918  630B 6A6C D5B7 6563 2D3A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20200514/426334d9/attachment.sig>


More information about the LibreOffice mailing list