MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / randomString

Function randomString

test/test_utf16_bench.c:29–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27long utf16_corpus_length = 0;
28
29uint16_t *randomString(int len) {
30 if (!utf16_corpus) {
31 FILE *handle = fopen("utf16_corpus.txt", "rb");
32 fseek(handle, 0, SEEK_END);
33 utf16_corpus_length = ftell(handle)/2;
34 assert(utf16_corpus_length > 0);
35 utf16_corpus = malloc(sizeof(uint16_t) * (utf16_corpus_length+1));
36 fseek(handle, 0, SEEK_SET);
37 fread(utf16_corpus, 2, utf16_corpus_length, handle);
38 fclose(handle);
39 utf16_corpus[utf16_corpus_length] = 0;
40 }
41 int startIdx = rand() % (utf16_corpus_length - len);
42 while((utf16_corpus[startIdx] & 0xFF00) == 0xDC00) {
43 ++startIdx;
44 if (startIdx + len > utf16_corpus_length) len = utf16_corpus_length - startIdx;
45 }
46 assert(len > 0);
47 uint16_t *s = malloc(sizeof(uint16_t) * (len+1));
48 memcpy(s, utf16_corpus + startIdx, len*2);
49 s[len] = 0;
50 while(((uint16_t)s[len-1] & 0xFF00) == 0xD800) { s[--len] = 0; }
51 assert(len >= 0);
52 return s;
53}
54
55int main() {
56 double t = 0;

Callers 1

mainFunction · 0.70

Calls 9

fopenFunction · 0.85
fseekFunction · 0.85
ftellFunction · 0.85
freadFunction · 0.85
fcloseFunction · 0.85
randFunction · 0.85
memcpyFunction · 0.85
assertFunction · 0.50
mallocFunction · 0.50

Tested by

no test coverage detected