Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix load too slow bug #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IronSublimate
Copy link

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

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

Copy link

@adishimoni8 adishimoni8 left a comment

Choose a reason for hiding this comment

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

Amazing.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants