vlib: fix remaining mutability errors

pull/3006/head
Alexander Medvednikov 2019-12-07 15:13:23 +03:00
parent 329485d4b6
commit c2814c1ada
3 changed files with 20 additions and 21 deletions

View File

@ -184,7 +184,6 @@ fn (cb &Clipboard) take_ownership(){
fn (cb mut Clipboard) set_text(text string) bool { fn (cb mut Clipboard) set_text(text string) bool {
if cb.window == Window(C.None) {return false} if cb.window == Window(C.None) {return false}
mut ret := false
cb.mutex.lock() cb.mutex.lock()
cb.text = text cb.text = text
cb.is_owner = true cb.is_owner = true

View File

@ -25,7 +25,7 @@ const (
*/ */
pub fn decode(data string) string { pub fn decode(data string) string {
buffer := malloc( data.len * 3 / 4 ) buffer := malloc( data.len * 3 / 4 )
return tos(buffer, decode_in_buffer(data, mut buffer) ) return tos(buffer, decode_in_buffer(data, buffer) )
} }
/** /**
@ -37,7 +37,7 @@ pub fn decode(data string) string {
*/ */
pub fn encode(data string) string { pub fn encode(data string) string {
buffer := malloc( 4 * ((data.len + 2) / 3) ) buffer := malloc( 4 * ((data.len + 2) / 3) )
return tos(buffer, encode_in_buffer(data, mut buffer)) return tos(buffer, encode_in_buffer(data, buffer))
} }
/** /**
@ -109,7 +109,7 @@ pub fn decode_in_buffer(data &string, buffer byteptr) int {
* @return the actual size of the encoded data in the buffer. * @return the actual size of the encoded data in the buffer.
* NB: this function does NOT allocate new memory, and is suitable for handling very large strings. * NB: this function does NOT allocate new memory, and is suitable for handling very large strings.
*/ */
pub fn encode_in_buffer(data &string, buffer mut byteptr) int { pub fn encode_in_buffer(data &string, buffer byteptr) int {
input_length := data.len input_length := data.len
output_length := 4 * ((input_length + 2) / 3) output_length := 4 * ((input_length + 2) / 3)

View File

@ -15,14 +15,14 @@ fn test_long_encoding(){
ebuffer := malloc( s_encoded.len ) ebuffer := malloc( s_encoded.len )
for i := 0; i < repeats; i++ { for i := 0; i < repeats; i++ {
resultsize := base64.encode_in_buffer(s_original, mut ebuffer) resultsize := base64.encode_in_buffer(s_original, ebuffer)
s += resultsize s += resultsize
assert resultsize == s_encoded.len assert resultsize == s_encoded.len
} }
dbuffer := malloc( s_decoded.len ) dbuffer := malloc( s_decoded.len )
for i := 0; i < repeats; i++ { for i := 0; i < repeats; i++ {
resultsize := base64.decode_in_buffer(s_encoded, mut dbuffer) resultsize := base64.decode_in_buffer(s_encoded, dbuffer)
s += resultsize s += resultsize
assert resultsize == s_decoded.len assert resultsize == s_decoded.len
} }