Skip to content

Commit 8787639

Browse files
committed
ANDROID: update build for performance
1 parent abbe3a6 commit 8787639

File tree

9 files changed

+191
-78
lines changed

9 files changed

+191
-78
lines changed

configure.ac

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ function checkPCRE() {
123123
fi
124124
}
125125

126-
function checkSearch() {
127-
have_saerch="maybe"
128-
AC_CHECK_HEADER(search.h, [have_search="yes"], [have_search="no"])
129-
if test x$have_search = xyes ; then
130-
AC_DEFINE(HAVE_SEARCH_H, 1, [Found GNU search.h])
131-
fi
132-
}
133-
134126
function defaultConditionals() {
135127
AM_CONDITIONAL(WITH_HILDON, false)
136128
AM_CONDITIONAL(WITH_CYGWIN_CONSOLE, false)
@@ -633,7 +625,6 @@ else
633625
buildConsole
634626
fi
635627

636-
checkSearch
637628
checkPCRE
638629
checkDebugMode
639630
checkForWindows

src/common/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ libsb_common_a_SOURCES = \
7777
scan.c scan.h \
7878
str.c str.h \
7979
tasks.c tasks.h \
80+
search.c search.h \
8081
var_uds.c var_uds.h \
8182
var_hash.c var_hash.h \
8283
keymap.c keymap.h \

src/common/search.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// Tree search generalized from Knuth (6.2.2) Algorithm T just like
4+
// the AT&T man page says.
5+
//
6+
// The node_t structure is for internal use only, lint doesn't grok it.
7+
//
8+
// Written by reading the System V Interface Definition, not the code.
9+
//
10+
// Totally public domain.
11+
//
12+
13+
#include <sys/cdefs.h>
14+
#include <assert.h>
15+
#include <stdlib.h>
16+
17+
#include "search.h"
18+
19+
typedef struct node {
20+
void *key;
21+
struct node *left, *right;
22+
} node_t;
23+
24+
/* Walk the nodes of a tree */
25+
tdestroy_recurse(node_t *root, tdestroy_cb freefct) {
26+
if (root->left != NULL) {
27+
tdestroy_recurse(root->left, freefct);
28+
}
29+
if (root->right != NULL) {
30+
tdestroy_recurse(root->right, freefct);
31+
}
32+
(*freefct) ((void *) root->key);
33+
free(root);
34+
}
35+
36+
/* Walk the nodes of a tree */
37+
void trecurse(const node_t *root, twalk_cb action, int level) {
38+
if (root->left == NULL && root->right == NULL) {
39+
action(root, leaf, level);
40+
} else {
41+
action(root, preorder, level);
42+
if (root->left != NULL) {
43+
trecurse(root->left, action, level + 1);
44+
}
45+
action(root, postorder, level);
46+
if (root->right != NULL) {
47+
trecurse(root->right, action, level + 1);
48+
}
49+
action(root, endorder, level);
50+
}
51+
}
52+
53+
/* find a node, or return 0 */
54+
void *tfind(const void *vkey, void **vrootp, tcompare_cb compar) {
55+
node_t **rootp = (node_t **)vrootp;
56+
57+
while (rootp != NULL && *rootp != NULL) {
58+
int r = (*compar)(vkey, (*rootp)->key);
59+
if (r == 0) {
60+
// found
61+
return *rootp;
62+
}
63+
rootp = (r < 0) ? &(*rootp)->left : &(*rootp)->right;
64+
}
65+
return NULL;
66+
}
67+
68+
/* find or insert datum into search tree */
69+
void *tsearch(const void *vkey, void **vrootp, tcompare_cb compar) {
70+
node_t **rootp = (node_t **) tfind(vkey, vrootp, compar);
71+
node_t *q;
72+
73+
if (rootp != NULL) {
74+
q = *rootp;
75+
} else {
76+
// key not found. make new node and link to old
77+
q = malloc(sizeof(node_t));
78+
if (q != 0) {
79+
*rootp = q;
80+
q->key = (void *)vkey;
81+
q->left = q->right = NULL;
82+
}
83+
}
84+
return q;
85+
}
86+
87+
void tdestroy(void *vroot, tdestroy_cb freefct) {
88+
node_t *root = (node_t *)vroot;
89+
if (root != NULL) {
90+
tdestroy_recurse(root, freefct);
91+
}
92+
}
93+
94+
/* Walk the nodes of a tree */
95+
void twalk(const void *vroot, twalk_cb action) {
96+
if (vroot != NULL && action != NULL) {
97+
trecurse(vroot, action, 0);
98+
}
99+
}

src/common/search.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// Written by J.T. Conklin <jtc@netbsd.org>
4+
// Public domain.
5+
//
6+
7+
#ifndef _SEARCH_H_
8+
#define _SEARCH_H_
9+
10+
#include <sys/cdefs.h>
11+
#include <sys/types.h>
12+
13+
typedef enum {
14+
preorder,
15+
postorder,
16+
endorder,
17+
leaf
18+
} VISIT;
19+
20+
typedef void (*twalk_cb) (const void *nodep, VISIT value, int level);
21+
typedef void (*tdestroy_cb) (void *__nodep);
22+
typedef int (*tcompare_cb) (const void *, const void *);
23+
24+
void *tfind(const void *vkey, void **vrootp, tcompare_cb compar);
25+
void *tsearch(const void *vkey, void **vrootp, tcompare_cb compar);
26+
void tdestroy(void *, tdestroy_cb cb);
27+
void twalk(const void *vroot, twalk_cb action);
28+
29+
#endif /* !_SEARCH_H_ */

src/common/var_hash.c

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
#include "common/var.h"
1313
#include "common/smbas.h"
1414
#include "common/var_hash.h"
15-
16-
#if defined(HAVE_SEARCH_H)
17-
#include <search.h>
15+
#include "common/search.h"
1816

1917
/**
2018
* Globals for callback access
@@ -46,35 +44,6 @@ typedef struct Node {
4644
Element *element;
4745
} Node;
4846

49-
#if !defined(tdestroy) && !defined(HAVE_TDESTROY)
50-
// tdestroy() is missing from MingW. include code from gnu clib _search.c
51-
52-
typedef struct node_t {
53-
void *key;
54-
struct node_t *left, *right;
55-
} node;
56-
57-
typedef void (*__free_fn_t) (void *__nodep);
58-
59-
tdestroy_recurse(node *root, __free_fn_t freefct) {
60-
if (root->left != NULL) {
61-
tdestroy_recurse(root->left, freefct);
62-
}
63-
if (root->right != NULL) {
64-
tdestroy_recurse(root->right, freefct);
65-
}
66-
(*freefct) ((void *) root->key);
67-
free(root);
68-
}
69-
70-
void tdestroy(void *vroot, __free_fn_t freefct) {
71-
node *root = (node *) vroot;
72-
if (root != NULL) {
73-
tdestroy_recurse (root, freefct);
74-
}
75-
}
76-
#endif
77-
7847
/**
7948
* Returns a new Element
8049
*/
@@ -293,31 +262,3 @@ void hash_write(const var_p_t var_p, int method, int handle) {
293262
}
294263
}
295264

296-
#else
297-
298-
// search.h not supported on this platform
299-
int hash_compare(const var_p_t var_a, const var_p_t var_b) {
300-
}
301-
int hash_is_empty(const var_p_t var_p) {
302-
}
303-
int hash_to_int(const var_p_t var_p) {
304-
}
305-
int hash_length(const var_p_t var_p) {
306-
}
307-
var_p_t hash_elem(const var_p_t var_p, int index) {
308-
}
309-
void hash_clear(const var_p_t var_p) {
310-
}
311-
void hash_free_var(var_p_t var_p) {
312-
}
313-
void hash_get_value(var_p_t base, var_p_t key, var_p_t *result) {
314-
}
315-
void hash_set(var_p_t dest, const var_p_t src) {
316-
}
317-
void hash_to_str(const var_p_t var_p, char *out, int max_len) {
318-
}
319-
void hash_write(const var_p_t var_p, int method, int handle) {
320-
}
321-
322-
#endif
323-

src/platform/android/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Download the GNU Public License (GPL) from www.gnu.org
66
#
77

8-
all-am: Makefile ant-build
8+
all-am: Makefile ndk-build-test
99

1010
ndk-build-test:
1111
(cd jni && ${NDK}/ndk-build NDK_DEBUG=1)
@@ -18,3 +18,7 @@ test: ant-build-test
1818
adb -a logcat -c && \
1919
adb -a shell am start net.sourceforge.smallbasic/net.sourceforge.smallbasic.MainActivity && \
2020
adb -a logcat)
21+
22+
clean-am:
23+
(cd jni && ${NDK}/ndk-build clean)
24+

src/platform/android/jni/Android.mk

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
JNI_PATH := $(call my-dir)
99
SB_HOME := $(JNI_PATH)/../../../..
1010
PNG_HOME := $(HOME)/android-sdk/libpng-1.6.12/png
11-
FREETYPE_HOME := $(HOME)/android-sdk/freetype-2.5.3/freetype
11+
FREETYPE_HOME := $(HOME)/android-sdk/freetype-2.5.3
1212

1313
include $(call all-subdir-makefiles)
1414
LOCAL_PATH := $(JNI_PATH)
@@ -18,17 +18,12 @@ LOCAL_MODULE := png
1818
LOCAL_SRC_FILES := $(PNG_HOME)/lib/libpng.a
1919
include $(PREBUILT_STATIC_LIBRARY)
2020

21-
include $(CLEAR_VARS)
22-
LOCAL_MODULE := freetype
23-
LOCAL_SRC_FILES := $(FREETYPE_HOME)/lib/libfreetype.a
24-
include $(PREBUILT_STATIC_LIBRARY)
25-
2621
include $(CLEAR_VARS)
2722
LOCAL_MODULE := smallbasic
2823
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1
2924
LOCAL_C_INCLUDES := $(SB_HOME) $(SB_HOME)/src \
30-
$(FREETYPE_HOME)/include \
31-
$(FREETYPE_HOME)/include/freetype2
25+
$(FREETYPE_HOME)/freetype/include \
26+
$(FREETYPE_HOME)/freetype/include/freetype2
3227
LOCAL_SRC_FILES := main.cpp \
3328
display.cpp \
3429
runtime.cpp \

src/platform/android/jni/common/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ LOCAL_SRC_FILES := \
5151
$(COMMON)/scan.c \
5252
$(COMMON)/str.c \
5353
$(COMMON)/tasks.c \
54+
$(COMMON)/search.c \
5455
$(COMMON)/var_uds.c \
5556
$(COMMON)/var_hash.c \
5657
$(COMMON)/keymap.c \
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SmallBASIC
2+
# Copyright(C) 2001-2014 Chris Warren-Smith.
3+
#
4+
# This program is distributed under the terms of the GPL v2.0 or later
5+
# Download the GNU Public License (GPL) from www.gnu.org
6+
#
7+
8+
LOCAL_PATH := $(call my-dir)
9+
include $(CLEAR_VARS)
10+
11+
LOCAL_C_INCLUDES := $(FREETYPE_HOME)/include \
12+
$(FREETYPE_HOME)/builds \
13+
$(FREETYPE_HOME)/include/config \
14+
$(FREETYPE_HOME)/include/freetype2
15+
LOCAL_MODULE := freetype
16+
LOCAL_CFLAGS := -Wall -std=gnu99 \
17+
"-DFT_CONFIG_CONFIG_H=<ftconfig.h>" \
18+
"-DFT2_BUILD_LIBRARY" \
19+
"-DFT_CONFIG_MODULES_H=<ftmodule.h>"
20+
21+
LOCAL_SRC_FILES:= \
22+
$(FREETYPE_HOME)/src/type1/type1.c \
23+
$(FREETYPE_HOME)/src/cid/type1cid.c \
24+
$(FREETYPE_HOME)/src/pfr/pfr.c \
25+
$(FREETYPE_HOME)/src/type42/type42.c \
26+
$(FREETYPE_HOME)/src/winfonts/winfnt.c \
27+
$(FREETYPE_HOME)/src/pcf/pcf.c \
28+
$(FREETYPE_HOME)/src/psaux/psaux.c \
29+
$(FREETYPE_HOME)/src/bdf/bdf.c \
30+
$(FREETYPE_HOME)/src/base/ftbbox.c \
31+
$(FREETYPE_HOME)/src/base/ftbitmap.c \
32+
$(FREETYPE_HOME)/src/base/ftglyph.c \
33+
$(FREETYPE_HOME)/src/base/ftstroke.c \
34+
$(FREETYPE_HOME)/src/base/ftxf86.c \
35+
$(FREETYPE_HOME)/src/base/ftbase.c \
36+
$(FREETYPE_HOME)/src/base/ftsystem.c \
37+
$(FREETYPE_HOME)/src/base/ftinit.c \
38+
$(FREETYPE_HOME)/src/base/ftgasp.c \
39+
$(FREETYPE_HOME)/src/raster/raster.c \
40+
$(FREETYPE_HOME)/src/sfnt/sfnt.c \
41+
$(FREETYPE_HOME)/src/smooth/smooth.c \
42+
$(FREETYPE_HOME)/src/autofit/autofit.c \
43+
$(FREETYPE_HOME)/src/truetype/truetype.c \
44+
$(FREETYPE_HOME)/src/cff/cff.c \
45+
$(FREETYPE_HOME)/src/psnames/psnames.c \
46+
$(FREETYPE_HOME)/src/pshinter/pshinter.c \
47+
$(FREETYPE_HOME)/src/gzip/ftgzip.c \
48+
$(FREETYPE_HOME)/src/lzw/ftlzw.c \
49+
$(FREETYPE_HOME)/src/lzw/ftzopen.c
50+
51+
52+
include $(BUILD_STATIC_LIBRARY)

0 commit comments

Comments
 (0)