Changeset 11487 for trunk/Mars


Ignore:
Timestamp:
07/20/11 17:58:40 (13 years ago)
Author:
tbretz
Message:
Optimized reverse copy procedure; added HasKey
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mbase/MFits.h

    r11461 r11487  
    294294    Table fTable;
    295295
    296     map<void*, Table::Column> fAddresses;
     296    typedef pair<void*, Table::Column> Address;
     297    typedef vector<Address> Addresses;
     298    //map<void*, Table::Column> fAddresses;
     299    Addresses fAddresses;
    297300
    298301    vector<char> fBufferRow;
     
    419422    }
    420423
     424    template<size_t N>
     425        void revcpy(char *dest, const char *src, int num)
     426    {
     427        const char *end = src + num*N;
     428        for (const char *ptr = src; ptr<end; ptr+=N, dest+=N)
     429            reverse_copy(ptr, ptr+N, dest);
     430    }
     431
    421432    bool GetRow(size_t row)
    422433    {
     
    425436            return good();
    426437
    427         for (map<void*,Table::Column>::const_iterator it=fAddresses.begin();
    428              it!=fAddresses.end(); it++)
     438        for (Addresses::const_iterator it=fAddresses.begin(); it!=fAddresses.end(); it++)
    429439        {
    430440            const Table::Column &c = it->second;
    431441
    432442            const char *src = fBufferRow.data() + c.offset;
    433             const char *end = src + c.num*c.size;
    434 
    435443            char *dest = reinterpret_cast<char*>(it->first);
    436             for (const char *ptr = src; ptr<end; ptr+=c.size, dest+=c.size)
    437                 reverse_copy(ptr, ptr+c.size, dest);
     444
     445            // Let the compiler do some optimization by
     446            // knowing the we only have 1, 2, 4 and 8
     447            switch (c.size)
     448            {
     449            case 1: memcpy   (dest, src, c.num*c.size); break;
     450            case 2: revcpy<2>(dest, src, c.num);        break;
     451            case 4: revcpy<4>(dest, src, c.num);        break;
     452            case 8: revcpy<8>(dest, src, c.num);        break;
     453            }
    438454        }
    439455
     
    452468    }
    453469
     470    static bool Compare(const Address &p1, const Address &p2)
     471    {
     472        return p1.first>p2.first;
     473    }
     474
    454475    template<typename T>
    455476    bool SetPtrAddress(const string &name, T *ptr, size_t cnt)
     
    480501        //     gLog << warn << "SetPtrAddress('" << name << "') - Pointer " << ptr << " already assigned." << endl;
    481502
    482         fAddresses[ptr] = fTable.cols[name];
    483 
     503        //fAddresses[ptr] = fTable.cols[name];
     504        fAddresses.push_back(make_pair(ptr, fTable.cols[name]));
     505        sort(fAddresses.begin(), fAddresses.end(), Compare);
    484506        return true;
    485507    }
     
    514536        //     gLog << warn << "SetPtrAddress('" << name << "') - Pointer " << ptr << " already assigned." << endl;
    515537
    516         fAddresses[ptr] = fTable.cols[name];
    517 
     538        //fAddresses[ptr] = fTable.cols[name];
     539        fAddresses.push_back(make_pair(ptr, fTable.cols[name]));
     540        sort(fAddresses.begin(), fAddresses.end(), Compare);
    518541        return true;
    519542    }
    520543
     544    bool     HasKey(const string &key) const { return fTable.HasKey(key); }
    521545    int64_t  GetInt(const string &key) const { return fTable.Get<int64_t>(key); }
    522546    uint64_t GetUInt(const string &key) const { return fTable.Get<uint64_t>(key); }
Note: See TracChangeset for help on using the changeset viewer.