From 7fc4fa089fe451db0e1d8fb47fc792e56694e7e9 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Tue, 4 May 2010 13:52:55 +0200 Subject: [PATCH] Avoid redundant buffer copies for get_record --- src/main/java/org/yaz4j/Record.java | 3 +-- src/main/native/zoom-extra.cpp | 7 ++----- src/main/native/zoom-extra.h | 6 +++--- src/main/swig/libyaz4j.i | 1 - 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index 3770132..2e99158 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -23,8 +23,7 @@ public class Record implements Cloneable { } public byte[] get(String type) { - SWIGTYPE_p_int length = null; - return yaz4jlib.ZOOM_record_get_bytes(record, type, length); + return yaz4jlib.ZOOM_record_get_bytes(record, type); } public String render() { diff --git a/src/main/native/zoom-extra.cpp b/src/main/native/zoom-extra.cpp index 0521686..2f4cb6f 100644 --- a/src/main/native/zoom-extra.cpp +++ b/src/main/native/zoom-extra.cpp @@ -1,12 +1,9 @@ #include "zoom-extra.h" #include -struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type, int *len) +struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type) { struct CharStarByteArray node; - const char* pageData = ZOOM_record_get(rec, type, len); - node.length = strlen(pageData); - node.data = (char*) malloc(node.length+1); - strcpy(node.data, pageData); + node.data = ZOOM_record_get(rec, type, &node.length); return node; } diff --git a/src/main/native/zoom-extra.h b/src/main/native/zoom-extra.h index 6d428a8..0792b9a 100644 --- a/src/main/native/zoom-extra.h +++ b/src/main/native/zoom-extra.h @@ -3,9 +3,9 @@ #include struct CharStarByteArray { - char* data; - long length; + const char* data; + int length; }; -struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type, int *len); +struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type); #endif diff --git a/src/main/swig/libyaz4j.i b/src/main/swig/libyaz4j.i index 61e4693..3e686e2 100644 --- a/src/main/swig/libyaz4j.i +++ b/src/main/swig/libyaz4j.i @@ -14,7 +14,6 @@ %typemap(jstype) CharStarByteArray "byte[]" %typemap(out) CharStarByteArray { $result = SWIG_JavaArrayOutSchar(jenv, (signed char*) $1.data, $1.length); - free((void*)$1.data); } %typemap(javaout) CharStarByteArray { return $jnicall; } %define YAZ_BEGIN_CDECL %enddef -- 1.7.10.4