forked from pyrocko/pyrocko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibmseed-2.19.6-speedread.patch
182 lines (161 loc) · 5.69 KB
/
libmseed-2.19.6-speedread.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
diff -ruN libmseed/libmseed.h libmseed_mod/libmseed.h
--- libmseed/libmseed.h 2019-06-19 10:59:29.000000000 +0200
+++ libmseed_mod/libmseed.h 2021-04-09 09:44:41.881346528 +0200
@@ -511,6 +511,7 @@
double samprate; /* Nominal sample rate (Hz) */
int64_t samplecnt; /* Number of samples in trace coverage */
void *datasamples; /* Data samples, 'numsamples' of type 'sampletype' */
+ size_t bufsize;
int64_t numsamples; /* Number of data samples in datasamples */
char sampletype; /* Sample type code: a, i, f, d */
void *prvtptr; /* Private pointer for general use, unused by libmseed */
diff -ruN libmseed/Makefile.win libmseed_mod/Makefile.win
--- libmseed/Makefile.win 2019-06-19 10:59:29.000000000 +0200
+++ libmseed_mod/Makefile.win 2021-04-09 09:44:41.881346528 +0200
@@ -5,9 +5,10 @@
NODEBUG=1
INCS = -I.
-OPTS = -D_CRT_SECURE_NO_WARNINGS
+OPTS = -D_CRT_SECURE_NO_WARNINGS -DWIN32
LIB = libmseed.lib
DLL = libmseed.dll
+CFLAGS = /Ox
OBJS= fileutils.obj \
genutils.obj \
diff -ruN libmseed/traceutils.c libmseed_mod/traceutils.c
--- libmseed/traceutils.c 2019-06-19 10:59:29.000000000 +0200
+++ libmseed_mod/traceutils.c 2021-04-09 09:44:41.881346528 +0200
@@ -437,6 +437,7 @@
mst_addmsr (MSTrace *mst, MSRecord *msr, flag whence)
{
int samplesize = 0;
+ size_t min_size;
if (!mst || !msr)
return -1;
@@ -465,13 +466,16 @@
return -1;
}
- mst->datasamples = realloc (mst->datasamples,
- (size_t) (mst->numsamples * samplesize + msr->numsamples * samplesize));
+ min_size = (size_t) (mst->numsamples * samplesize + msr->numsamples * samplesize);
- if (mst->datasamples == NULL)
- {
- ms_log (2, "mst_addmsr(): Cannot allocate memory\n");
- return -1;
+ if (min_size > mst->bufsize) {
+ mst->datasamples = realloc (mst->datasamples, min_size*2);
+ if (mst->datasamples == NULL)
+ {
+ ms_log (2, "mst_addmsr(): Cannot allocate memory\n");
+ return -1;
+ }
+ mst->bufsize = min_size*2;
}
}
@@ -548,6 +552,7 @@
flag whence)
{
int samplesize = 0;
+ size_t min_size;
if (!mst)
return -1;
@@ -568,13 +573,15 @@
return -1;
}
- mst->datasamples = realloc (mst->datasamples,
- (size_t) (mst->numsamples * samplesize + numsamples * samplesize));
-
- if (mst->datasamples == NULL)
- {
- ms_log (2, "mst_addspan(): Cannot allocate memory\n");
- return -1;
+ min_size = (size_t) (mst->numsamples * samplesize + numsamples * samplesize);
+ if (min_size > mst->bufsize) {
+ mst->datasamples = realloc (mst->datasamples, min_size*2);
+ if (mst->datasamples == NULL)
+ {
+ ms_log (2, "mst_addspan(): Cannot allocate memory\n");
+ return -1;
+ }
+ mst->bufsize = min_size*2;
}
}
@@ -1108,6 +1115,7 @@
float *fdata;
double *ddata;
int64_t idx;
+ size_t bufsize;
if (!mst)
return -1;
@@ -1160,11 +1168,13 @@
}
/* Reallocate buffer for reduced size needed */
- if (!(mst->datasamples = realloc (mst->datasamples, (size_t) (mst->numsamples * sizeof (int32_t)))))
+ bufsize = (size_t) (mst->numsamples * sizeof (int32_t));
+ if (!(mst->datasamples = realloc (mst->datasamples, bufsize)))
{
ms_log (2, "mst_convertsamples: cannot re-allocate buffer for sample conversion\n");
return -1;
}
+ mst->bufsize = bufsize;
}
mst->sampletype = 'i';
@@ -1184,11 +1194,13 @@
fdata[idx] = (float)ddata[idx];
/* Reallocate buffer for reduced size needed */
- if (!(mst->datasamples = realloc (mst->datasamples, (size_t) (mst->numsamples * sizeof (float)))))
+ bufsize = (size_t) (mst->numsamples * sizeof (float));
+ if (!(mst->datasamples = realloc (mst->datasamples, bufsize)))
{
ms_log (2, "mst_convertsamples: cannot re-allocate buffer after sample conversion\n");
return -1;
}
+ mst->bufsize = bufsize;
}
mst->sampletype = 'f';
@@ -1197,7 +1209,8 @@
/* Convert to 64-bit doubles */
else if (type == 'd')
{
- if (!(ddata = (double *)malloc ((size_t) (mst->numsamples * sizeof (double)))))
+ bufsize = (size_t) (mst->numsamples * sizeof (double));
+ if (!(ddata = (double *)malloc (bufsize)))
{
ms_log (2, "mst_convertsamples: cannot allocate buffer for sample conversion to doubles\n");
return -1;
@@ -1219,6 +1232,7 @@
}
mst->datasamples = ddata;
+ mst->bufsize = bufsize;
mst->sampletype = 'd';
} /* Done converting to 64-bit doubles */
@@ -1659,7 +1673,7 @@
int trpackedrecords = 0;
int64_t trpackedsamples = 0;
int samplesize;
- int64_t bufsize;
+ size_t bufsize;
hptime_t preservestarttime = 0;
double preservesamprate = 0.0;
@@ -1745,21 +1759,22 @@
mst->starttime = msr->starttime;
samplesize = ms_samplesize (mst->sampletype);
- bufsize = (mst->numsamples - trpackedsamples) * samplesize;
+ bufsize = (size_t) (mst->numsamples - trpackedsamples) * samplesize;
if (bufsize)
{
memmove (mst->datasamples,
(char *)mst->datasamples + (trpackedsamples * samplesize),
- (size_t)bufsize);
+ bufsize);
- mst->datasamples = realloc (mst->datasamples, (size_t)bufsize);
+ mst->datasamples = realloc (mst->datasamples, bufsize);
if (mst->datasamples == NULL)
{
ms_log (2, "mst_pack(): Cannot (re)allocate datasamples buffer\n");
return -1;
}
+ mst->bufsize = bufsize;
}
else
{