Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory efficient to_string system #88

Open
KCreate opened this issue Mar 31, 2022 · 0 comments
Open

Memory efficient to_string system #88

KCreate opened this issue Mar 31, 2022 · 0 comments

Comments

@KCreate
Copy link
Owner

KCreate commented Mar 31, 2022

  • StringBuffer, BytesBuffer mutable alternatives for String, Bytes

    • Can be converted to const string or bytes by freezing
  • to_string(io) method declared on Value class

    • can be overridden to implement custom to_string behaviour
    • receives an IO object to write string contents to
    • IO is an interface implementing basic read / write access to "stuff"
    • io is backed by a string buffer
    • Base Value class contains to_string() method with no io, allocating the string buffer
interface IO {
  func to_string {
    const buf = StringBuffer.new()
    to_string(buf)
    buf.freeze()
  }
}

class Person {
  property name
  property age
  
  func to_string(io) {
    io << "Person name={name} age={age}"
    io
  }
}

const p1 = Person("alice", 24)
const p2 = Person("bob", 22)

p1.to_string() // Person name=alice age=24
p2.to_string() // Person name=bob age=22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant