File tree Expand file tree Collapse file tree 2 files changed +12
-17
lines changed
Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -31,9 +31,9 @@ typedef struct
3131typedef struct
3232{
3333 UmkaDynArray (Point ) points ;
34+ int64_t actLen ;
3435 char * name ;
3536 Style style ;
36- int64_t reserved ;
3737} Series ;
3838
3939
Original file line number Diff line number Diff line change 1616
1717 Series* = struct {
1818 points: []Point
19+ actLen: int
1920 name: str
2021 style: Style
21- reserved: int
2222 }
2323
2424 Grid* = struct {
@@ -48,30 +48,25 @@ type (
4848)
4949
5050fn (s: ^Series) clear*() {
51- s.points = []Point{}
52- }
53-
54- fn (s: ^Series) reserve*(size: int) {
55- s.points = make([]Point, size)
56- s.reserved = size
51+ s.points = make([]Point, 256)
52+ s.actLen = 0
5753}
5854
5955fn (s: ^Series) trim() {
60- if s.reserved > 0 {
61- s.points = slice(s.points, 0, len(s.points) - s.reserved)
62- s.reserved = 0
56+ if s.actLen < len(s.points) {
57+ s.points = slice(s.points, 0, s.actLen)
6358 }
6459}
6560
6661fn (s: ^Series) add*(x, y: real) {
6762 if len(s.points) == 0 {
68- s.points = []Point{Point{x, y}}
69- } else if s.reserved > 0 {
70- s.points[len(s.points) - s.reserved] = Point{x, y}
71- s.reserved--
72- } else {
73- s.points = append(s.points, Point{x, y})
63+ s.clear()
64+ }
65+ if s.actLen >= len(s.points) {
66+ s.points = append(s.points, make([]Point, len(s.points)))
7467 }
68+ s.points[s.actLen] = Point{x, y}
69+ s.actLen++
7570}
7671
7772fn init*(numSeries: int = 1, kind: int = STYLE_LINE): Plot {
You can’t perform that action at this time.
0 commit comments