builtin: replace `isnil` calls for perfomance

pull/4614/head
Alexander Medvednikov 2020-04-27 07:13:36 +02:00
parent e523540f3a
commit ef26f27753
3 changed files with 5 additions and 5 deletions

View File

@ -50,7 +50,7 @@ pub fn panic(s string) {
}
pub fn eprintln(s string) {
if isnil(s.str) {
if s.str == 0 {
panic('eprintln(NIL)')
}
$if !windows {
@ -65,7 +65,7 @@ pub fn eprintln(s string) {
}
pub fn eprint(s string) {
if isnil(s.str) {
if s.str == 0 {
panic('eprint(NIL)')
}
$if !windows {

View File

@ -333,7 +333,7 @@ pub fn (s string) u64() u64 {
// ==
fn (s string) eq(a string) bool {
if isnil(s.str) {
if s.str == 0 {
// should never happen
panic('string.eq(): nil string')
}

View File

@ -116,7 +116,7 @@ pub fn (_str string) to_wide() &u16 {
$if windows {
num_chars := (C.MultiByteToWideChar(CP_UTF8, 0, _str.str, _str.len, 0, 0))
mut wstr := &u16(malloc((num_chars + 1) * 2)) // sizeof(wchar_t)
if !isnil(wstr) {
if wstr != 0 {
C.MultiByteToWideChar(CP_UTF8, 0, _str.str, _str.len, wstr, num_chars)
C.memset(&byte(wstr) + num_chars * 2, 0, 2)
}
@ -139,7 +139,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
$if windows {
num_chars := C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, 0, 0, 0, 0)
mut str_to := malloc(num_chars + 1)
if !isnil(str_to) {
if str_to != 0 {
C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, str_to, num_chars, 0, 0)
C.memset(str_to + num_chars, 0, 1)
}