Skip to content

Commit db9c761

Browse files
committed
Changed Sketch struct to not use pointers
1 parent 2f2e2a6 commit db9c761

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

arduino/builder/sketch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func SketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
8888
mergedSource += mainSrc + "\n"
8989
lineOffset++
9090

91-
for _, file := range *sk.OtherSketchFiles {
91+
for _, file := range sk.OtherSketchFiles {
9292
src, err := getSource(file)
9393
if err != nil {
9494
return 0, "", err
@@ -107,7 +107,7 @@ func SketchCopyAdditionalFiles(sketch *sketch.Sketch, destPath *paths.Path, over
107107
return errors.Wrap(err, "unable to create a folder to save the sketch files")
108108
}
109109

110-
for _, file := range *sketch.AdditionalFiles {
110+
for _, file := range sketch.AdditionalFiles {
111111
relpath, err := sketch.FullPath.RelTo(file)
112112
if err != nil {
113113
return errors.Wrap(err, "unable to compute relative path to the sketch for the item")

arduino/builder/sketch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ func TestCopyAdditionalFiles(t *testing.T) {
122122
require.Equal(t, s2.AdditionalFiles.Len(), 1)
123123

124124
// save file info
125-
info1, err := paths.New(s2.AdditionalFiles.AsStrings()[0]).Stat()
125+
info1, err := s2.AdditionalFiles[0].Stat()
126126
require.Nil(t, err)
127127

128128
// copy again
129129
err = builder.SketchCopyAdditionalFiles(s1, tmp, nil)
130130
require.Nil(t, err)
131131

132132
// verify file hasn't changed
133-
info2, err := paths.New(s2.AdditionalFiles.AsStrings()[0]).Stat()
133+
info2, err := s2.AdditionalFiles[0].Stat()
134134
require.Equal(t, info1.ModTime(), info2.ModTime())
135135
}

arduino/sketch/sketch.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ type Sketch struct {
3434
MainFile *paths.Path
3535
FullPath *paths.Path // FullPath is the path to the Sketch folder
3636
BuildPath *paths.Path
37-
OtherSketchFiles *paths.PathList // Sketch files that end in .ino other than main file
38-
AdditionalFiles *paths.PathList
39-
RootFolderFiles *paths.PathList // All files that are in the Sketch root
37+
OtherSketchFiles paths.PathList // Sketch files that end in .ino other than main file
38+
AdditionalFiles paths.PathList
39+
RootFolderFiles paths.PathList // All files that are in the Sketch root
4040
Metadata *Metadata
4141
}
4242

@@ -80,9 +80,9 @@ func New(path *paths.Path) (*Sketch, error) {
8080
MainFile: mainFile,
8181
FullPath: path,
8282
BuildPath: GenBuildPath(path),
83-
OtherSketchFiles: new(paths.PathList),
84-
AdditionalFiles: new(paths.PathList),
85-
RootFolderFiles: new(paths.PathList),
83+
OtherSketchFiles: paths.PathList{},
84+
AdditionalFiles: paths.PathList{},
85+
RootFolderFiles: paths.PathList{},
8686
}
8787

8888
err := sketch.checkSketchCasing()
@@ -139,9 +139,9 @@ func New(path *paths.Path) (*Sketch, error) {
139139
}
140140
}
141141

142-
sort.Sort(sketch.AdditionalFiles)
143-
sort.Sort(sketch.OtherSketchFiles)
144-
sort.Sort(sketch.RootFolderFiles)
142+
sort.Sort(&sketch.AdditionalFiles)
143+
sort.Sort(&sketch.OtherSketchFiles)
144+
sort.Sort(&sketch.RootFolderFiles)
145145

146146
if err := sketch.importMetadata(); err != nil {
147147
return nil, fmt.Errorf("importing sketch metadata: %s", err)

commands/instances.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,17 +849,17 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
849849
}
850850

851851
otherSketchFiles := make([]string, sketch.OtherSketchFiles.Len())
852-
for i, file := range *sketch.OtherSketchFiles {
852+
for i, file := range sketch.OtherSketchFiles {
853853
otherSketchFiles[i] = file.String()
854854
}
855855

856856
additionalFiles := make([]string, sketch.AdditionalFiles.Len())
857-
for i, file := range *sketch.AdditionalFiles {
857+
for i, file := range sketch.AdditionalFiles {
858858
additionalFiles[i] = file.String()
859859
}
860860

861861
rootFolderFiles := make([]string, sketch.RootFolderFiles.Len())
862-
for i, file := range *sketch.RootFolderFiles {
862+
for i, file := range sketch.RootFolderFiles {
863863
rootFolderFiles[i] = file.String()
864864
}
865865

legacy/builder/filter_sketch_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type FilterSketchSource struct {
3434
func (s *FilterSketchSource) Run(ctx *types.Context) error {
3535
fileNames := paths.NewPathList()
3636
fileNames.Add(ctx.Sketch.MainFile)
37-
for _, file := range *ctx.Sketch.OtherSketchFiles {
37+
for _, file := range ctx.Sketch.OtherSketchFiles {
3838
fileNames = append(fileNames, file)
3939
}
4040

legacy/builder/types/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
211211
opts.SetPath("sketchLocation", ctx.SketchLocation)
212212
var additionalFilesRelative []string
213213
if ctx.Sketch != nil {
214-
for _, f := range *ctx.Sketch.AdditionalFiles {
214+
for _, f := range ctx.Sketch.AdditionalFiles {
215215
absPath := ctx.SketchLocation.Parent()
216216
relPath, err := f.RelTo(absPath)
217217
if err != nil {

0 commit comments

Comments
 (0)