Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:47
    straight-shoota closed #12051
  • 13:47
    straight-shoota closed #12050
  • 12:17
    beta-ziliani edited #7318
  • May 15 08:43
    r00ster91 closed #7318
  • May 15 08:17
    r00ster91 closed #7690
  • May 14 17:01
    Blacksmoke16 labeled #11995
  • May 14 13:03
    webhive closed #12055
  • May 14 10:19
    straight-shoota milestoned #12051
  • May 14 10:00
    I3oris edited #12051
  • May 14 08:45
    oprypin review_requested #11977
  • May 13 23:29
    Blacksmoke16 unlabeled #12061
  • May 13 22:56
    Blacksmoke16 edited #12061
  • May 13 22:56
    Blacksmoke16 edited #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 opened #12061
  • May 13 20:14
    straight-shoota labeled #12060
  • May 13 20:14
    straight-shoota labeled #12060
  • May 13 20:14
    straight-shoota opened #12060
Isaac Sloan
@elorest
Or with starts_with?
https://carc.in/#/r/2j9c
Ghost
@ghost~55586c4815522ed4b3e08557
@elorest Also works with a Char, => no String object allocation (https://carc.in/#/r/2j9d)
From IRC (bridge bot)
@FromIRC
<Papierkorb> @bew, Except for the additional branching in the string version, as for a string literal, there's no allocation happening
<Papierkorb> @bew, read that as "both are fine", neither allocate extra memory. The Char version is sliightly faster of course, but apart from that..
Ghost
@ghost~55586c4815522ed4b3e08557
Papierkorb: even for the String object (a few bytes I now)
?
yeah for sure
From IRC (bridge bot)
@FromIRC
<Papierkorb> @bew, the String is constant and exists completely in the .rodata afaik, thus, no run-time overhead of it being there
Ghost
@ghost~55586c4815522ed4b3e08557
I wasn't speaking about the bytes of the string, but the crystal-lang String object (which has a pointer to .rodata to the actual string)
From IRC (bridge bot)
@FromIRC
<Papierkorb> .rodata exists anyway and is just copied into memory by the ELF loader. Technically, it's slightly more involved than that. But before you notice that, you probably have many other things to optimize first ;⁠) - String is pretty much a Tuple(UInt8*, Int32) in terms of size, so it's not even really a reference. Also one of the reasons you can't inherit from String.
LuckyChicken
@LuckyChicken91_twitter
who here is finding .empty? at a string unnecessary? because you can write if string==""faster than if string.empty?
Ghost
@ghost~55586c4815522ed4b3e08557
@LuckyChicken91_twitter shorter, but not necessarily faster
From IRC (bridge bot)
@FromIRC
<Papierkorb> No, String#empty? is fine and having to write foo == "" is crap.
<Papierkorb> Not to mention consistency with other Enumerable types
Isaac Sloan
@elorest
@bew good point.
LuckyChicken
@LuckyChicken91_twitter
oh so comparing if string.empty? and if string=="" in benchmark then =="" would be slower?
From IRC (bridge bot)
@FromIRC
<Papierkorb> Of course.
LuckyChicken
@LuckyChicken91_twitter
aah okay good to know
From IRC (bridge bot)
@FromIRC
<Papierkorb> But that's not the reason for it. It's idiomatic to ask something if it's empty.
<Papierkorb> It's less idiomatic to ask if something equals something empty
Ghost
@ghost~55586c4815522ed4b3e08557
Papierkorb: in program.cr String is noted as inheriting from reference, then its instance_vars are declared, but I can't find any other "weird" stuff about string.. can you give me some pointer on what is really special about it?
From IRC (bridge bot)
@FromIRC
<Papierkorb> @bew, also hard-declaring the inst_vars in the compiler makes it kinda special ;⁠)
Akzhan Abdulin
@akzhan

hi all :)

where am i wrong? i want to get index of element that less than 16:
https://play.crystal-lang.org/#/r/2j9g

arr = [ 1, 4, 16, 25 ]

idx = arr.bsearch_index { |x| x < 16 }

p idx
prints nil
Ghost
@ghost~55586c4815522ed4b3e08557
@akzhan it's weird, it doesn't try all elements: https://carc.in/#/r/2j9t
Thanks Papierkorb!
From IRC (bridge bot)
@FromIRC
<oprypin> @bew, Papierkorb, so what's really happening with a string is it's a pointer to some bytes, the first 4 of which are size and the rest are contents - the "some bytes" can be in heap or rodata (not 100% sure)
<oprypin> wow except it's not 4 bytes but 3*4 bytes {TYPE_ID, bytesize.to_i, size.to_i}
Tim Foerster
@tonobo
hiho, i've a question releated to compile time checks. It corrected that your doing such checks, e. g handling possible nil access? So if conditions on instance variables are not working, is there any possibility to skip this compile time check convert into runtime checks?
From IRC (bridge bot)
@FromIRC
<Papierkorb> @oprypin: String stores the string data just after the three @vars. It doesn't have a pointer to it, as the address to it is really "pointerof(String) + 12 Bytes"
Ghost
@ghost~55586c4815522ed4b3e08557
oprypin: I thing that only the content can be in heap or rodata, the rest (+ the pointer) is allocated by the GC with GC.malloc_atomic
From IRC (bridge bot)
@FromIRC
Ghost
@ghost~55586c4815522ed4b3e08557
wut
From IRC (bridge bot)
@FromIRC
<Papierkorb> @oprypin: And yes, the data can be anywhere. I expect the @size (which is the size in Chars) to be correctly initialized by the compiler, so it doesn't have to be written to (which would cause a segfault within .rodata) later on
Tim Foerster
@tonobo
oprypin: i know the situation but isn't quite inperfomant by allocation each on heap? what happens with arrays?
From IRC (bridge bot)
@FromIRC
<oprypin> @bew, there is no rest https://carc.in/#/r/2ja2
<RX14> ^
Ghost
@ghost~55586c4815522ed4b3e08557
yeah I just understood
From IRC (bridge bot)
@FromIRC
<oprypin> @tonobo, your worries are caused by some misunderstanding, there is no problem with this, in fact llvm probably eliminates this entirely
<hightower2> @sdogruyol: there?
<RX14> a string has no pointer
<RX14> it simply has a header + data which are always contiguous
<oprypin> well actually it does, a String is only a pointer
<oprypin> to what you just said
<RX14> it is a pointer
<RX14> it doesn't HAVE a pointer
Ghost
@ghost~55586c4815522ed4b3e08557
yep
very interesting
From IRC (bridge bot)
@FromIRC
<oprypin> indeed