Skip to content

fix load too slow bug - #68

Open
IronSublimate wants to merge 1 commit into
dorian3d:masterfrom
IronSublimate:master
Open

fix load too slow bug#68
IronSublimate wants to merge 1 commit into
dorian3d:masterfrom
IronSublimate:master

Conversation

@IronSublimate

Copy link
Copy Markdown

In OpenCV, cv::FileNode::operator and cv::FileNodeIterator::operator+=(int) has O(n) time complexity. So I changed fn[i] to iterator.The total time complexity is changed from O(n^2) to O(n)
The OpenCV FileNode code can find here.
In OpenCV4, the FileNode::operator calls FileNodeIterator::operator+=(int):

FileNode FileNode::operator[](int i) const
{
    if(!fs)
        return FileNode();

    CV_Assert( isSeq() );

    int sz = (int)size();
    CV_Assert( 0 <= i && i < sz );

    FileNodeIterator it = begin();
    it += i; //Here OpenCV use operator+=

    return *it;
}

but the FileNodeIterator::operator+=(int) is not O(1) .It uses FOR to get i.

FileNodeIterator& FileNodeIterator::operator += (int _ofs)
{
    CV_Assert( _ofs >= 0 );
    for( ; _ofs > 0; _ofs-- )
        this->operator ++();
    return *this;
}

@llschloesser

Copy link
Copy Markdown

@IronSublimate and @yhabib29 This same fix can be applied to improve database loading as well, yeah?

@adishimoni8 adishimoni8 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants