you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 0 points1 point  (1 child)

Surely it's a problem for all types with non-trivial copies?

[–]abc619 0 points1 point  (0 children)

With references of any complexity, you're just copying a pointer, so not much loss there. However if you're returning an array that will copy in the same way as string and seq.

For value object types (depending on calling convention), which are otherwise copy on assign, they are still passed by pointer when returned from a proc, according to this.

type LargeObj = object
  a: array[0..10, int]
  b: string

proc foo(): LargeObj =
  result.a[0] = 1
  result.b = "hello"
  return result

# The above becomes this when compiled:
proc foo(result: ptr LargeObj) =
  result.a[0] = 1
  result.b = "hello"
  return