Closed Bug 1613564 Opened 4 years ago Closed 4 years ago

Rust nsACString should be able to produce a String without copying

Categories

(Core :: XPCOM, task)

task
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: zbraniecki, Assigned: emilio)

References

Details

Attachments

(1 file, 1 obsolete file)

Came up while working on bug 1560038.

From :emilio on #rust on Matrix:

zbraniecki: but then you want a no-copy way to turn that nsACString into a String
zbraniecki: and I'm not sure we have that... But it seems conceptually possible
zbraniecki: I think we should be able to add an nsCString::into_string(self) or such
Flags: needinfo?(emilio)

There are ~4 things that an nsACString can represent:

  1. A fully owned char* buffer.
  2. A char* that points into data that somebody else owns.
  3. A char* that points at a static char[] (which is really a special case of number 2).
  4. An nsStringBuffer object (potentially) shared by other nsACString objects.

So you can really only do this in a zero-copy way for the first representation. If you're OK with that limitation (and realizing that--at least in the C++ code--most strings are probably using the last representation), I guess the API makes sense?

Yes, this would need to return an Option or a Cow or something... For Zibi's purposes I think (1) is the case he'll hit.

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Flags: needinfo?(emilio)

Will land the first bit for now.

Keywords: leave-open
Pushed by ealvarez@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c123ce0ac63c
Minor nsstring cleanup / tweaks. r=froydnj
Attachment #9128648 - Attachment is obsolete: true

should we close this now?

Probably.

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: