Guild icon
DDraceNetwork
Development / developer
Development discussion. Logged to https://ddnet.tw/irclogs/ Connected with DDNet's IRC channel, Matrix room and GitHub repositories — IRC: #ddnet on Quakenet | Matrix: #ddnet-developer:matrix.org GitHub: https://github.com/ddnet
Between 2018-11-27 00:00:00Z and 2018-11-28 00:00:00Z
Avatar
I love installing gentoo, you just partition, mount, unpack a tar and the package manager finishes it up for you
Avatar
ok wat
15:17
The magic scripts that make DDNet run. Contribute to ddnet/ddnet-scripts development by creating an account on GitHub.
15:18
the deslugify2 function wtf
15:18
for special_char in re.findall('(-([\d]+)-)', name): name = name.replace(special_char[0], chr(int(special_char[1]))) return name (is python 3 but doesn't differ much to python 2 code) (edited)
15:19
why easy if you can do it in a hard way
Avatar
@Peekabooo that might be a port of my C implementation 😄
16:52
hm, yours ends up making lots of copies of name, doesn't it?
16:52
I'd prefer a way where only one string is built
Avatar
you mean from the generated opcode?
Avatar
I just mean that each time you call name.replace it makes a copy, doesn't it?
Avatar
sec checking
16:59
not really a copy but just load_fast and store_fast
16:59
same as modifying a variable
17:01
and less than half the amount of instructions in general
Avatar
sure, because your logic is hidden in the CALL_FUNCTION to findall and isn't STORE_FAST doing the copy then?
Avatar
store_fast is used when you use f.e. n += c, n += unichr(i), i = i * 10 + int(c), i = 0 in your code too
Avatar
actually the replace_char is going to do the copy internally of course
17:02
and the returned object just replaces the old one
17:06
well, yours is faster anyway @Peekabooo 😃
17:07
what about encoding though, will it be correct?
17:07
I believe you need to do unichr and later encode('utf-8') and then it's not faster anymore
17:07
otherwise some strange characters will fail
Avatar
wrote below the code that the code was python 3
17:09
python 3 has no unichr anymore, only chr since unicode is default
Avatar
ah, but we use py2
Avatar
yeah was just an example what would be better in my opinion
17:10
at least it's 3 times faster
Avatar
Not with py2
Avatar
which comes from less conditions and only updating one variable instead of 3
17:11
sec I'll check
Avatar
anyway, yours is clearer so I'll add it, time difference is small
17:14
thanks
17:14
well only twice as fast in python 2
17:15
for special_char in re.findall('(-([\d]+)-)', name): name = name.replace(special_char[0], unichr(int(special_char[1]))) return name.encode('utf-8') (edited)
17:15
with the utf-8 decoding
17:15
oops ok encode instead of decode
Avatar
GitHub Gist: instantly share code, notes, and snippets.
17:19
but I'm getting close results in favour of your function with your passed string too
17:21
ok for 0,1,2 special characters replace is faster for me, 3 is kinda equal, 4+ clearly favours your implementation (edited)
Exported 44 message(s)