Closed Bug 78398 Opened 25 years ago Closed 17 years ago

[API] implement `string generators'

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX
Future

People

(Reporter: scc, Assigned: jag+mozilla)

References

Details

Attachments

(2 files)

String generators make conversion operations able to skip the intermediate buffer and generate their result directly into the final destination, e.g., compare nsString result = NS_ConvertASCIItoUCS2(aCString); // |aCString| converted into the local buffer of the anonymous temporary // then copied again to |result| // proposed... nsString result = GenerateUCS2fromASCII(aCString); // assignment from a generator asks the generator for the length, // makes that much space available, then calls the generator to // fill that space May be able to transparently upgrade some existing converters to this behavior after generators exist, though situations where the result is used _as_ a string will have to be fixed, e.g., nsresult ExamineString( const nsAString& aStringToExamine ); ExamineString( NS_ConvertASCIItoUCS2(aCString) ); If |NS_Convert...| were upgraded, the compiler would catch cases like this, and we would have to substitute, e.g., ExamineString( nsAutoString(NS_ConvertASCIItoUCS2(aCString)) ); Eventually, we would also add generator concatenations. String modifying routines that take string parameters for input, in particular |Insert|, |Replace|, |Append|, and the other assignment forms, would be doubled to also accept generators. Consider the win in myString.Append( GenerateUCS2fromASCII(aCString) ); // or myString.Insert( ToLowerCase(aServerName), pos ); Naming scheme for generators to be decided, several different alternatives illustrated above. Generators might depend on extent strings (as in all the examples above) and so we should exploit the |Promises| (to be renamed to |IsDependentOn|) scheme to avoid circular assignment collision. Note also: a string is _not_ a generator, and as always we should strive to provide automatic conversions (even though it's easy to see how a string could generate itself) except perhaps if where that might be needed to make generator concatenations work. Typical implementations where a call can accept a generator or a string might simply fall through to the generator case, e.g., void T::DoSomethingWith( nsAStringGenerator& aGenerator ) { // ... } inline void T::DoSomethingWith( const nsAString& aString ) { DoSomethingWith( PumpString(aString) ); // |PumpString| or |GenerateSelf| or ... } Hmmm, of course this skirts the |const| issue. If a generator is stream-like, then the generating operation must not be |const|, and so the above construction fails. One would have to say nsStringPump generator(aString); DoSomethingWith(generator); But if a generator is required to be stateless, then we don't have to go to this extra trouble. We would have to consider how generators can assign into multi-fragment destinations, though, since a stateless generator couldn't be called repeatedly. If we go this route, iterators are the natural solution I think. The actual assignment would happen with something like (all names invented for exposition) iterator destination = this->MakeSpaceAvailable(generator.Length()); generator.WriteTo(destination); Many extent operations are candidates for generator style implementations: case conversions, line ending conversions, white space compression, et al.
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.2
Should read: "and as always we should strive _not_ to provide automatic conversions"
Blocks: 73009
Summary: implement `string generators' → [API] implement `string generators'
re-targeting milestones, starting from a clean slate
Target Milestone: mozilla0.9.2 → ---
All planned string API fixes need to be in by mozilla1.0.
Target Milestone: --- → mozilla1.0
Here's an example solution using generators for the problem Chris Blizzard is solving in bug #70207 extern char* custom_allocate( PRUint32 ); GenerateUTF8fromUCS2 generate_utf8_into(unicodeString); PRUint32 converted_length = converter.Length(); if ( char* result = custom_allocate(converted_length+1) ) { generate_utf8_into(result); result[converted_length] = '\0'; return result; } What do you think, Chris? Would this meet your needs?
I can't say because it's so convoluted that I can't tell what it does. Also, does the amount of extra code balance out the memory usage from an extra malloc?
sr=waterson
2nd attachment checked in, generators are now part of the build. Now to make strings use them.
Bugs targeted at mozilla1.0 without the mozilla1.0 keyword moved to mozilla1.0.1 (you can query for this string to delete spam or retrieve the list of bugs I've moved)
Target Milestone: mozilla1.0 → mozilla1.0.1
giving up ancient string bugs to the new string owner. jag, you'll want to sort through these and see which ones still apply and go with or against the direction in which you intend strings evolve
Assignee: scc → jaggernaut
Status: ASSIGNED → NEW
retargeting
Target Milestone: mozilla1.0.1 → Future
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → WONTFIX
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: