mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
Implement strings the way Go itself does
This makes string slicing cheap.
This commit is contained in:
+2
-2
@@ -6,8 +6,8 @@
|
||||
|
||||
#define print(buf, len) write(STDOUT_FILENO, buf, len)
|
||||
|
||||
void __go_printstring(string_t *str) {
|
||||
write(STDOUT_FILENO, str->buf, str->len);
|
||||
void __go_printstring(string_t str) {
|
||||
write(STDOUT_FILENO, str.buf, str.len);
|
||||
}
|
||||
|
||||
void __go_printint(intgo_t n) {
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t len; // TODO: size_t (or, let max string size depend on target/flag)
|
||||
uint8_t buf[]; // variable size
|
||||
uint32_t len; // TODO: size_t (or, let max string size depend on target/flag)
|
||||
uint8_t *buf; // points to string buffer itself
|
||||
} string_t;
|
||||
|
||||
typedef int32_t intgo_t; // may be 64-bit
|
||||
|
||||
Reference in New Issue
Block a user