Skip to content

Look through references for non-bool comparison operators - #510

Merged
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:12-nonbool-comparison-refs
Oct 14, 2026
Merged

nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:12-nonbool-comparison-refs

Conversation

@lucic71

@lucic71 lucic71 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@lucic71
lucic71 marked this pull request as draft October 9, 2026 17:49
@lucic71

lucic71 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

This is not a very nice solution because it does more string surgeries on the trait implementation path.

The reason we have to do so many string surgeries for Ord, PartialEq, Clone is that those traits receive a &Self and to call user methods we need to convert that &Self into a &Ptr<Self>. The only way to get a Ptr is from a Value, which is very awkward because we need to do: Rc::new(RefCell::new( T { f1: self.f1.clone(), ... } ).as_pointer().

Getting rid of this situation means implementing our own Ord, ParitalEq, Clone. It's not very nice, but I think this will greatly improve the performance. Take Clone for example. Now is:

impl Clone for T {
  fn clone(&self) -> Self {
    // Extra Rc/RefCell allocation + clone on every field
    let __src: Value<T> = Rc::new(RefCell::new(T { a: self.a.clone(), ... }));
    // all of this to be able to call a method on &Ptr<Self>
    T::copy_from(__src.as_pointer())
  }
}

Faster version:

impl OurClone for T {
  fn clone(src: Ptr<Self>) -> Self {
    T::copy_from(src)
  }
}

@lucic71
lucic71 marked this pull request as ready for review October 9, 2026 21:46
@nunoplopes
nunoplopes merged commit 15eae42 into Cpp2Rust:master Oct 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants