Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot committed Jan 3, 2025
1 parent 4298424 commit 9364c5b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions vlib/v/live/common.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,15 @@ pub mut:
// live.info - give user access to program's LiveReloadInfo struct,
// so that the user can set callbacks, read meta information, etc.
pub fn info() &LiveReloadInfo {
if C.g_live_info != 0 {
return unsafe { &LiveReloadInfo(C.g_live_info) }
if C.g_live_info == 0 {
// When the current program is not compiled with -live, simply
// return a new empty struct LiveReloadInfo in order to prevent
// crashes. In this case, the background reloader thread is not
// started, and the structure LiveReloadInfo will not get updated.
// All its fields will be 0, but still safe to access.
unsafe {
C.g_live_info = int(&LiveReloadInfo{})
}
}
// When the current program is not compiled with -live, simply
// return a new empty struct LiveReloadInfo in order to prevent
// crashes. In this case, the background reloader thread is not
// started, and the structure LiveReloadInfo will not get updated.
// All its fields will be 0, but still safe to access.
mut x := &LiveReloadInfo{}
unsafe {
mut p := &u64(&C.g_live_info)
*p = u64(x)
_ = p
}
return x
return unsafe { &LiveReloadInfo(C.g_live_info) }
}

0 comments on commit 9364c5b

Please sign in to comment.