From be29fc44e0bbd18563775bf75182a740f2b8332c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 7 Aug 2014 22:06:12 -0700 Subject: [PATCH] Avoid repeated creation of a simple RegExp object. --- web/text_layer_builder.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index 19b54ccf6..03fbcf7ad 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -22,6 +22,12 @@ var FIND_SCROLL_OFFSET_LEFT = -400; var MAX_TEXT_DIVS_TO_RENDER = 100000; var RENDER_DELAY = 200; // ms +var NonWhitespaceRegexp = /\S/; + +function isAllWhitespace(str) { + return !NonWhitespaceRegexp.test(str); +} + /** * TextLayerBuilder provides text-selection functionality for the PDF. * It does this by creating overlay divs over the PDF text. These divs @@ -118,7 +124,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() { var style = styles[geom.fontName]; var textDiv = document.createElement('div'); this.textDivs.push(textDiv); - if (!/\S/.test(geom.str)) { + if (isAllWhitespace(geom.str)) { textDiv.dataset.isWhitespace = true; return; }