Giter Site home page Giter Site logo

Comments (8)

joachimschmidt557 avatar joachimschmidt557 commented on August 15, 2024 1

@data-man Yes, that would aid the usability of FontStyle if it would be represented as an integer. But those will be small functions which will be almost-surely inlined in a release build, so the overhead of an additional function call won't be there, only the overhead of the bitwise operation then.

I'll leave this proposal open until some benchmarks have been integrated into the library. From then on, we can test the performance of checking attributes/setting attributes/checking equality/subset of attributes/etc. And from these results, we can then proceed to select the appropriate representation of FontStyle

from ansi-term.

joachimschmidt557 avatar joachimschmidt557 commented on August 15, 2024 1

@data-man If you want, feel free to implement that.

from ansi-term.

joachimschmidt557 avatar joachimschmidt557 commented on August 15, 2024 1

@data-man Yup, don't know why this hasn't occurred to me yet. This means we can get the best of both worlds. I guess we can close this issue now.

from ansi-term.

data-man avatar data-man commented on August 15, 2024

I think bitwise operations will decrease output's performance.

from ansi-term.

joachimschmidt557 avatar joachimschmidt557 commented on August 15, 2024

@data-man That may be right for checking a specific field of the FontStyle, i.e. checking whether font_style.bold == true. When using integers, we have an additional overhead of one bitwise operation in addition to the comparison.

But for other purposes, this has increased performance:

  • checking if multiple fields are set
  • checking for equality (includes checking isDefault)
  • checking if a given font style has at least the attributes of another font style (no attributes were removed)

All operations are turned into O(1) operations instead of O(n) where n is the number of fields.

from ansi-term.

data-man avatar data-man commented on August 15, 2024

When using integers, we have an additional overhead of one bitwise operation in addition to the comparison.

And for convenience, some helpers will be needed: isBold/setBold, etc.

from ansi-term.

data-man avatar data-man commented on August 15, 2024

@joachimschmidt557
I think helpers for RGB type are more important. Maybe in new module.
Rust's rgb24 as example.

from ansi-term.

data-man avatar data-man commented on August 15, 2024
pub const FontStyle = packed struct {
...
const Self = @This();
...
pub fn asUInt(self: Self) u11 {
    return @bitCast(u11, self);
}
...

?

from ansi-term.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.