You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/10/31 23:22:23 UTC
[08/14] lucy git commit: Add helper converting Vector to slice of
strings.
Add helper converting Vector to slice of strings.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e00c8810
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e00c8810
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e00c8810
Branch: refs/heads/master
Commit: e00c88102d51c6fb427a986dce8082f47aa8c614
Parents: b3a0f3e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Oct 21 19:09:17 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Oct 23 16:42:12 2015 -0700
----------------------------------------------------------------------
go/lucy/analysis.go | 9 ++-------
go/lucy/lucy.go | 14 ++++++++++++++
go/lucy/plan.go | 10 +---------
3 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/e00c8810/go/lucy/analysis.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis.go b/go/lucy/analysis.go
index 134c081..61465b4 100644
--- a/go/lucy/analysis.go
+++ b/go/lucy/analysis.go
@@ -56,11 +56,6 @@ func (a *AnalyzerIMP) Split(text string) []string {
input := (*C.cfish_String)(clownfish.GoToClownfish(text, unsafe.Pointer(C.CFISH_STRING), false))
defer C.cfish_decref(unsafe.Pointer(input))
retvalCF := C.LUCY_Analyzer_Split(self, input)
- size := C.CFISH_Vec_Get_Size(retvalCF)
- retvalGO := make([]string, int(size))
- for i := 0; i < int(size); i++ {
- elem := C.CFISH_Vec_Fetch(retvalCF, C.size_t(i))
- retvalGO[i] = clownfish.CFStringToGo(unsafe.Pointer(elem))
- }
- return retvalGO
+ defer C.cfish_decref(unsafe.Pointer(retvalCF))
+ return vecToStringSlice(retvalCF)
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/e00c8810/go/lucy/lucy.go
----------------------------------------------------------------------
diff --git a/go/lucy/lucy.go b/go/lucy/lucy.go
index 42dc119..585a192 100644
--- a/go/lucy/lucy.go
+++ b/go/lucy/lucy.go
@@ -612,3 +612,17 @@ func GOLUCY_Inverter_Invert_Doc(inverter *C.lucy_Inverter, doc *C.lucy_Doc) {
C.LUCY_Inverter_Add_Field(inverter, inventry)
}
}
+
+// Turn a Vector of Clownfish Strings into a slice of Go string. NULL
+// elements in the Vector are not allowed.
+func vecToStringSlice(v *C.cfish_Vector) []string {
+ if v == nil {
+ return nil
+ }
+ length := int(C.CFISH_Vec_Get_Size(v))
+ slice := make([]string, length)
+ for i := 0; i < length; i++ {
+ slice[i] = clownfish.CFStringToGo(unsafe.Pointer(C.CFISH_Vec_Fetch(v, C.size_t(i))))
+ }
+ return slice
+}
http://git-wip-us.apache.org/repos/asf/lucy/blob/e00c8810/go/lucy/plan.go
----------------------------------------------------------------------
diff --git a/go/lucy/plan.go b/go/lucy/plan.go
index 1f030db..58912bf 100644
--- a/go/lucy/plan.go
+++ b/go/lucy/plan.go
@@ -24,18 +24,10 @@ package lucy
import "C"
import "unsafe"
-import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
-
func (s *SchemaIMP) AllFields() []string {
self := (*C.lucy_Schema)(unsafe.Pointer(s.TOPTR()))
fieldsCF := C.LUCY_Schema_All_Fields(self)
defer C.cfish_decref(unsafe.Pointer(fieldsCF))
- numFields := C.CFISH_Vec_Get_Size(fieldsCF)
- fields := make([]string, int(numFields))
- for i := C.size_t(0); i < numFields; i++ {
- fields[i] =
- clownfish.CFStringToGo(unsafe.Pointer(C.CFISH_Vec_Fetch(fieldsCF, i)))
- }
- return fields
+ return vecToStringSlice(fieldsCF)
}