Skip to content

Commit

Permalink
#406: convert remaining relevant memchr calls to VMX_MEMCHR/VMX_HASCHR
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Aug 28, 2017
1 parent af74f27 commit 3f66b79
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 16 deletions.
5 changes: 4 additions & 1 deletion dom/media/ogg/OggCodecState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "VideoUtils.h"
#include <algorithm>

#include "mozilla-config.h"
#include "plvmx.h"

// On Android JellyBean, the hardware.h header redefines version_major and
// version_minor, which breaks our build. See:
// https://bugzilla.mozilla.org/show_bug.cgi?id=912702#c6
Expand Down Expand Up @@ -115,7 +118,7 @@ bool OggCodecState::AddVorbisComment(MetadataTags* aTags,
const char* aComment,
uint32_t aLength)
{
const char* div = (const char*)memchr(aComment, '=', aLength);
const char* div = (const char*)VMX_MEMCHR(aComment, '=', aLength);
if (!div) {
LOG(LogLevel::Debug, ("Skipping comment: no separator"));
return false;
Expand Down
5 changes: 4 additions & 1 deletion gfx/ots/src/post.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include "maxp.h"

#include "mozilla-config.h"
#include "plvmx.h"

// post - PostScript
// http://www.microsoft.com/typography/otspec/post.htm

Expand Down Expand Up @@ -95,7 +98,7 @@ bool ots_post_parse(Font *font, const uint8_t *data, size_t length) {
if (strings + 1 + string_length > strings_end) {
return OTS_FAILURE_MSG("Bad string length %d", string_length);
}
if (std::memchr(strings + 1, '\0', string_length)) {
if (VMX_HASCHR(strings + 1, '\0', string_length)) {
return OTS_FAILURE_MSG("Bad string of length %d", string_length);
}
post->names.push_back(
Expand Down
16 changes: 12 additions & 4 deletions ipc/chromium/src/third_party/libevent/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
#include "evbuffer-internal.h"
#include "bufferevent-internal.h"

#include "mozilla-config.h"
#include "plvmx.h"

/* some systems do not have MAP_FAILED */
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
Expand Down Expand Up @@ -1299,7 +1302,7 @@ evbuffer_strchr(struct evbuffer_ptr *it, const char chr)
size_t i = it->_internal.pos_in_chain;
while (chain != NULL) {
char *buffer = (char *)chain->buffer + chain->misalign;
char *cp = memchr(buffer+i, chr, chain->off-i);
char *cp = VMX_MEMCHR(buffer+i, chr, chain->off-i);
if (cp) {
it->_internal.chain = chain;
it->_internal.pos_in_chain = cp - buffer;
Expand All @@ -1317,16 +1320,21 @@ evbuffer_strchr(struct evbuffer_ptr *it, const char chr)
static inline char *
find_eol_char(char *s, size_t len)
{
#if TENFOURFOX_VMX
#warning using accelerated VMX libevent
#define CHUNK_SZ 1024
#else
#define CHUNK_SZ 128
#endif
/* Lots of benchmarking found this approach to be faster in practice
* than doing two memchrs over the whole buffer, doin a memchr on each
* char of the buffer, or trying to emulate memchr by hand. */
char *s_end, *cr, *lf;
s_end = s+len;
while (s < s_end) {
size_t chunk = (s + CHUNK_SZ < s_end) ? CHUNK_SZ : (s_end - s);
cr = memchr(s, '\r', chunk);
lf = memchr(s, '\n', chunk);
cr = VMX_MEMCHR(s, '\r', chunk);
lf = VMX_MEMCHR(s, '\n', chunk);
if (cr) {
if (lf && lf < cr)
return lf;
Expand Down Expand Up @@ -2528,7 +2536,7 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con
const unsigned char *start_at =
chain->buffer + chain->misalign +
pos._internal.pos_in_chain;
p = memchr(start_at, first,
p = VMX_MEMCHR(start_at, first,
chain->off - pos._internal.pos_in_chain);
if (p) {
pos.pos += p - start_at;
Expand Down
5 changes: 4 additions & 1 deletion media/libogg/src/ogg_framing.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <string.h>
#include <ogg/ogg.h>

#include "mozilla-config.h"
#include "plvmx.h"

/* A complete description of Ogg framing exists in docs/framing.html */

int ogg_page_version(const ogg_page *og){
Expand Down Expand Up @@ -735,7 +738,7 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
oy->bodybytes=0;

/* search for possible capture */
next=memchr(page+1,'O',bytes-1);
next=VMX_MEMCHR(page+1,'O',bytes-1);
if(!next)
next=oy->data+oy->fill;

Expand Down
5 changes: 4 additions & 1 deletion modules/zlib/src/gzread.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "gzguts.h"

#include "mozilla-config.h"
#include "plvmx.h"

/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
Expand Down Expand Up @@ -523,7 +526,7 @@ char * ZEXPORT gzgets(file, buf, len)

/* look for end-of-line in current output buffer */
n = state->x.have > left ? left : state->x.have;
eol = (unsigned char *)memchr(state->x.next, '\n', n);
eol = (unsigned char *)VMX_MEMCHR(state->x.next, '\n', n);
if (eol != NULL)
n = (unsigned)(eol - state->x.next) + 1;

Expand Down
5 changes: 4 additions & 1 deletion netwerk/base/nsURLHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "mozilla/Preferences.h"
#include "prnetdb.h"

#include "mozilla-config.h"
#include "plvmx.h"

using namespace mozilla;

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -902,7 +905,7 @@ net_ParseMediaType(const nsACString &aMediaTypeStr,
// include a comma, so this check makes us a bit more tolerant.

if (type != typeEnd &&
memchr(type, '/', typeEnd - type) != nullptr &&
VMX_HASCHR(type, '/', typeEnd - type) &&
(aStrict ? (net_FindCharNotInSet(start + consumed, end, HTTP_LWS) == end) :
(strncmp(type, "*/*", typeEnd - type) != 0))) {
// Common case here is that aContentType is empty
Expand Down
5 changes: 4 additions & 1 deletion netwerk/base/nsURLParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "nsString.h"
#include "nsCRT.h"

#include "mozilla-config.h"
#include "plvmx.h"

using namespace mozilla;

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -524,7 +527,7 @@ nsAuthURLParser::ParseUserInfo(const char *userinfo, int32_t userinfoLen,
return NS_OK;
}

const char *p = (const char *) memchr(userinfo, ':', userinfoLen);
const char *p = (const char *) VMX_MEMCHR(userinfo, ':', userinfoLen);
if (p) {
// userinfo = <username:password>
if (p == userinfo) {
Expand Down
5 changes: 4 additions & 1 deletion netwerk/protocol/http/nsHttpChunkedDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "nsHttpChunkedDecoder.h"
#include <algorithm>

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla {
namespace net {

Expand Down Expand Up @@ -92,7 +95,7 @@ nsHttpChunkedDecoder::ParseChunkRemaining(char *buf,

*bytesConsumed = 0;

char *p = static_cast<char *>(memchr(buf, '\n', count));
char *p = static_cast<char *>(VMX_MEMCHR(buf, '\n', count));
if (p) {
*p = 0;
count = p - buf; // new length
Expand Down
5 changes: 4 additions & 1 deletion netwerk/protocol/http/nsHttpTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include "nsISchedulingContext.h"
#include <algorithm>

#include "mozilla-config.h"
#include "plvmx.h"

#ifdef MOZ_WIDGET_GONK
#include "NetStatistics.h"
#endif
Expand Down Expand Up @@ -1500,7 +1503,7 @@ nsHttpTransaction::ParseHead(char *buf,
// otherwise we can assume that we don't have a HTTP/0.9 response.

MOZ_ASSERT (mHttpResponseMatched);
while ((eol = static_cast<char *>(memchr(buf, '\n', count - *countRead))) != nullptr) {
while ((eol = static_cast<char *>(VMX_MEMCHR(buf, '\n', count - *countRead))) != nullptr) {
// found line in range [buf:eol]
len = eol - buf + 1;

Expand Down
5 changes: 4 additions & 1 deletion netwerk/streamconv/converters/nsMultiMixedConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "nsContentSecurityManager.h"
#include "nsHttp.h"

#include "mozilla-config.h"
#include "plvmx.h"

//
// Helper function for determining the length of data bytes up to
// the next multipart token. A token is usually preceded by a LF
Expand Down Expand Up @@ -1187,7 +1190,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
}

mContentLength = UINT64_MAX; // XXX what if we were already called?
while (cursorLen && (newLine = (char *) memchr(cursor, nsCRT::LF, cursorLen))) {
while (cursorLen && (newLine = (char *) VMX_MEMCHR(cursor, nsCRT::LF, cursorLen))) {
// adjust for linefeeds
if ((newLine > cursor) && (newLine[-1] == nsCRT::CR) ) { // CRLF
lineFeedIncrement = 2;
Expand Down
5 changes: 4 additions & 1 deletion security/certverifier/NSSCertDBTrustDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

#include "CNNICHashWhitelist.inc"

#include "mozilla-config.h"
#include "plvmx.h"

using namespace mozilla;
using namespace mozilla::pkix;

Expand Down Expand Up @@ -314,7 +317,7 @@ GetOCSPAuthorityInfoAccessLocation(PLArenaPool* arena,
const SECItem& location = current->name.other;
// (location.len + 1) must be small enough to fit into a uint32_t,
// but we limit it to a smaller bound to reduce OOM risk.
if (location.len > 1024 || memchr(location.data, 0, location.len)) {
if (location.len > 1024 || VMX_HASCHR(location.data, 0, location.len)) {
// Reject embedded nulls. (NSS doesn't do this)
return Result::ERROR_CERT_BAD_ACCESS_LOCATION;
}
Expand Down
5 changes: 4 additions & 1 deletion security/nss/lib/zlib/gzread.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "gzguts.h"

#include "mozilla-config.h"
#include "plvmx.h"

/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
Expand Down Expand Up @@ -581,7 +584,7 @@ char * ZEXPORT gzgets(file, buf, len)

/* look for end-of-line in current output buffer */
n = state->have > left ? left : state->have;
eol = memchr(state->next, '\n', n);
eol = VMX_MEMCHR(state->next, '\n', n);
if (eol != NULL)
n = (unsigned)(eol - state->next) + 1;

Expand Down
5 changes: 4 additions & 1 deletion xpcom/io/nsEscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "nsCRT.h"
#include "plstr.h"

#include "mozilla-config.h"
#include "plvmx.h"

static const char hexCharsUpper[] = "0123456789ABCDEF";
static const char hexCharsUpperLower[] = "0123456789ABCDEFabcdef";

Expand Down Expand Up @@ -529,7 +532,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray<char16_t>& aForbidden,
return aStr;
}

#define ISHEX(c) memchr(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1)
#define ISHEX(c) VMX_HASCHR(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1)

bool
NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags,
Expand Down

0 comments on commit 3f66b79

Please sign in to comment.