Closed Bug 52721 Opened 24 years ago Closed 24 years ago

|nsSlidingSubstring| needs to be constructable from a literal it can't own

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: scc, Assigned: scc)

Details

Attachments

(4 files)

|nsSlidingSubstring| needs to be constructable from a literal it can't own ... this is required for use in the parser.
Status: NEW → ASSIGNED
Vidur, these files work in my tests; I'll want to factor other spots (i.e., the thing currently called |nsSharedString|) in the string code to use the new general utilities for allocating an object contiguously with some string data. In the mean time, you can give me an r= for these (if they meet your standards) and you can start using them even before I can get them into the tree ... which is closed as I write this. You'll probably want to adjust the keywords and whiteboard status according to your priority for getting these changes into the tree.
Suggestion for a distance method for iterators: PRInt32 distance( nsReadingIterator<CharT>& other ) { if ( mOwningString != other.mOwningString ) { return kBadIterator; } nsReadingIterator<CharT> start, end; nsReadableFragment<CharT> cur; mOwningString->GetReadableFragment( cur, kFirstFragment ); do { if ( this.mFragment == cur ) { start = this; end = other; } else if ( other.mFragment == cur ) { start = other; end = this; } } while ( mOwningString->GetReadableFragment( cur, kNextFragment ) ); PRInt32 diff = 0; while ( !SameFragment( start, end ) ) { PRInt32 fraglength = start.size_forward( ); diff += fraglength; start.advance( fraglength ); } diff += (start.get( ) - end.get( )); return diff; }
flip the last line to |end.get()-start.get()| and I buy it. r=scc. with the caveat that sooner or later I'll rewrite this to something very like |CalculateHash| in the atom table implementation. In the mean time, this will do. It belongs in "nsAlgorithm.h"
My suggestion for the |Distance| function ... from email discussion with Vidur, please excuse ugly narrow email formatting template <class CharT> class CalculateLength { public: CalculateLength() : mDistance(0) { } size_t GetDistance() const { return mDistance; } PRUint32 write( const CharT*, PRUint32 N ) { mDistance += N; return N; } private: size_t mDistance; }; template <class CharT> size_t Distance( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { CalculateLength<CharT> sink; nsReadingIterator<CharT> fromBegin(aStart); copy_string(fromBegin, aEnd, sink); return sink.GetDistance(); }
For scc's Distance method, need to add typedef CharT value_type; to the class CalculateLength. I put it in nsReadableUtils.h to avoid cross-dependencies between nsAlgorithm.h and nsAReadableString.h.
we checked all this in with your parser work, as I recall, Vidur
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: