[Webkit-unassigned] [Bug 63541] New: TextPosition refactoring: Merge ZeroBasedNumber and OneBasedNumber classes

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jun 28 09:56:53 PDT 2011


https://bugs.webkit.org/show_bug.cgi?id=63541

           Summary: TextPosition refactoring: Merge ZeroBasedNumber and
                    OneBasedNumber classes
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Unspecified
        OS/Version: Unspecified
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: WebCore JavaScript
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: peter.rybin at gmail.com
                CC: ap at webkit.org


JavaScriptCore/wtf/text/TextPosition.h has dual types: [Zero/One]BasedNumber and TextPosition[0/1]. Intended only for transition phase, these dual types now ought to be merged down together.
This is a step 1.

Classes ZeroBasedNumber and OneBasedNumber should be replaced with one class BasedNumber (or maybe "NumberWithBase?").
In source file TextPositions.h old classes should be replaced with the following text:

"
class BasedNumber {
public:
    static BasedNumber fromZeroBasedInt(int zeroBasedInt) { return BasedNumber(zeroBasedInt); }
    static BasedNumber fromOneBasedInt(int oneBasedInt) { return BasedNumber(oneBasedInt - 1); }

    BasedNumber() {}

    int zeroBasedInt() const { return m_value0; }
    int oneBasedInt() const { return m_value0 + 1; }

    int convertAsOneBasedInt() const { return m_value0 + 1; }
    int convertAsZeroBasedInt() const { return m_value0; }

    BasedNumber convertToOneBased() const { return *this; }
    BasedNumber convertToZeroBased() const { return *this; }

    bool operator==(BasedNumber other) { return m_value0 == other.m_value0; }
    bool operator!=(BasedNumber other) { return !((*this) == other); }

    static BasedNumber base() { return BasedNumber(0); }
    static BasedNumber belowBase() { return BasedNumber(-1); }

private:
    BasedNumber(int value0) : m_value0(value0) {}
    int m_value0;
};

typedef BasedNumber ZeroBasedNumber;
typedef BasedNumber OneBasedNumber;
"


P.s. next steps could be:
1. make TextPosition no longer template -- inline its only possible actual parameter BasedNumber;
2. inline such typedefs as "typedef BasedNumber ZeroBasedNumber;" and "typedef TextPosition TextPosition0;" etc throughout source base;
3. inline trivial methods BasedNumber::convertTo[Zero/One]Based.

Methods DocumentParser::lineNumber currently return "int" (0-based), they should better return BasedNumber instead.
Fixing bug in XMLDocumentParserQt  ( https://bugs.webkit.org/show_bug.cgi?id=63540 ) is a good thing to do before these refactorings above.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list