Skip to content

Commit

Permalink
Merge pull request #5 from tiendc/improve-FindMissingItemIDs
Browse files Browse the repository at this point in the history
Improve FindMissingItemIDs by checking empty slice first
  • Loading branch information
tiendc authored Dec 18, 2023
2 parents 7b0908a + 5dbb994 commit 0b52ad5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
6 changes: 6 additions & 0 deletions templates/boilv4/mysql/103_model_utils.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (s {{$alias.UpSingular}}Slice) FindItemByID(id {{$column.Type}}) *{{$alias.
// FindMissingItemIDs find all item IDs that are not in the list
// NOTE: the input ID slice should contain unique values
func (s {{$alias.UpSingular}}Slice) FindMissingItemIDs(expectedIDs []{{$column.Type}}) []{{$column.Type}} {
if len(s) == 0 {
return expectedIDs
}
result := []{{$column.Type}}{}
mapChk := s.ToIDMap()
for _, id := range expectedIDs {
Expand Down Expand Up @@ -100,6 +103,9 @@ func (s {{$alias.UpSingular}}Slice) FindItemByID(id {{$column.Type}}) *{{$alias.
// FindMissingItemIDs find all item IDs that are not in the list
// NOTE: the input ID slice should contain unique values
func (s {{$alias.UpSingular}}Slice) FindMissingItemIDs(expectedIDs []{{$column.Type}}) []{{$column.Type}} {
if len(s) == 0 {
return expectedIDs
}
result := []{{$column.Type}}{}
mapChk := s.ToIDMap()
for _, id := range expectedIDs {
Expand Down
9 changes: 0 additions & 9 deletions templates/boilv4/mysql/singleton/boil_extra.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,3 @@ func SplitInChunksBySize[T any](slice []T, chunkSize int) [][]T {
func unsafeGetString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

func unsafeGetBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}
6 changes: 6 additions & 0 deletions templates/boilv4/postgres/103_model_utils.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (s {{$alias.UpSingular}}Slice) FindItemByID(id {{$column.Type}}) *{{$alias.
// FindMissingItemIDs find all item IDs that are not in the list
// NOTE: the input ID slice should contain unique values
func (s {{$alias.UpSingular}}Slice) FindMissingItemIDs(expectedIDs []{{$column.Type}}) []{{$column.Type}} {
if len(s) == 0 {
return expectedIDs
}
result := []{{$column.Type}}{}
mapChk := s.ToIDMap()
for _, id := range expectedIDs {
Expand Down Expand Up @@ -100,6 +103,9 @@ func (s {{$alias.UpSingular}}Slice) FindItemByID(id {{$column.Type}}) *{{$alias.
// FindMissingItemIDs find all item IDs that are not in the list
// NOTE: the input ID slice should contain unique values
func (s {{$alias.UpSingular}}Slice) FindMissingItemIDs(expectedIDs []{{$column.Type}}) []{{$column.Type}} {
if len(s) == 0 {
return expectedIDs
}
result := []{{$column.Type}}{}
mapChk := s.ToIDMap()
for _, id := range expectedIDs {
Expand Down
9 changes: 0 additions & 9 deletions templates/boilv4/postgres/singleton/boil_extra.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,3 @@ func SplitInChunksBySize[T any](slice []T, chunkSize int) [][]T {
func unsafeGetString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

func unsafeGetBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}

0 comments on commit 0b52ad5

Please sign in to comment.