Skip to content

Commit c7a6c1c

Browse files
authored
Merge pull request #27 from TeamNewPipe/revert-our-changes-and-use-firemasterk
2 parents e9d656d + 2a27a17 commit c7a6c1c

24 files changed

+1990
-1613
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/maven.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on:
12+
push:
13+
branches: [ "master" ]
14+
pull_request:
15+
branches: [ "master" ]
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up JDK 11
25+
uses: actions/setup-java@v3
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Build with Maven
31+
run: mvn -B package --file pom.xml

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
This is a fork of [nanojson](https://github.com/mmastrac/nanojson) for use by NewPipe(Extractor). It has the following changes:
44

5-
- It returns an empty `JsonObject` or `JsonArray` by default instead of `null`, preventing `NullPointerException`s.
6-
- It accepts JS-like JSON, such as `{ this: 'is', an: 'example' }`.
75
- Added ``JsonArray#streamAs`` and ``JsonArray#streamAsJsonObjects`` shortcut methods.
6+
- Various performance improvements borrowed from [@FireMasterK's fork](https://github.com/FireMasterK/nanojson).

checkstyle.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
</module>
2121

2222
<module name="LineLength">
23-
<property name="max" value="120" />
24-
<property name="tabWidth" value="4" />
23+
<property name="max" value="150" />
2524
</module>
2625

2726
<!-- If you set the basedir property below, then all reported file names
@@ -70,7 +69,7 @@
7069
<!-- Checks for Javadoc comments. -->
7170
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
7271
<module name="JavadocMethod">
73-
<property name="scope" value="public" />
72+
<property name="accessModifiers" value="public" />
7473
<property name="allowMissingParamTags" value="true" />
7574
<property name="allowMissingReturnTag" value="true" />
7675
</module>

pom.xml

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,35 @@
1313
<artifactId>nanojson</artifactId>
1414
<packaging>jar</packaging>
1515
<name>nanojson</name>
16-
<version>1.8-SNAPSHOT</version>
16+
<version>1.11-SNAPSHOT</version>
1717

1818
<properties>
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
21+
<maven.compiler.target>11</maven.compiler.target>
22+
<maven.compiler.source>11</maven.compiler.source>
2123
</properties>
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter</artifactId>
28+
<version>5.13.4</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>ch.randelshofer</groupId>
33+
<artifactId>fastdoubleparser</artifactId>
34+
<version>2.0.1</version>
35+
<scope>compile</scope>
36+
</dependency>
37+
</dependencies>
2238

2339
<reporting>
2440
<plugins>
2541
<plugin>
2642
<groupId>org.apache.maven.plugins</groupId>
2743
<artifactId>maven-javadoc-plugin</artifactId>
28-
<version>3.3.0</version>
44+
<version>3.11.3</version>
2945
<reportSets>
3046
<reportSet>
3147
<id>html</id>
@@ -44,7 +60,7 @@
4460
<plugin>
4561
<groupId>org.apache.maven.plugins</groupId>
4662
<artifactId>maven-checkstyle-plugin</artifactId>
47-
<version>3.1.2</version>
63+
<version>3.6.0</version>
4864
<configuration>
4965
<configLocation>checkstyle.xml</configLocation>
5066
<propertyExpansion>basedir=${basedir}</propertyExpansion>
@@ -66,7 +82,7 @@
6682
<plugin>
6783
<groupId>org.apache.maven.plugins</groupId>
6884
<artifactId>maven-surefire-report-plugin</artifactId>
69-
<version>2.22.2</version>
85+
<version>3.5.3</version>
7086
<reportSets>
7187
<reportSet>
7288
<reports>
@@ -77,21 +93,12 @@
7793
</plugin>
7894
</plugins>
7995
</reporting>
80-
81-
<dependencies>
82-
<dependency>
83-
<groupId>junit</groupId>
84-
<artifactId>junit</artifactId>
85-
<version>4.13.2</version>
86-
<scope>test</scope>
87-
</dependency>
88-
</dependencies>
8996
<build>
9097
<plugins>
9198
<plugin>
9299
<groupId>org.apache.maven.plugins</groupId>
93100
<artifactId>maven-source-plugin</artifactId>
94-
<version>3.2.1</version>
101+
<version>3.3.1</version>
95102
<executions>
96103
<execution>
97104
<id>attach-sources</id>
@@ -104,7 +111,7 @@
104111
<plugin>
105112
<groupId>org.apache.maven.plugins</groupId>
106113
<artifactId>maven-javadoc-plugin</artifactId>
107-
<version>3.3.0</version>
114+
<version>3.11.3</version>
108115
<executions>
109116
<execution>
110117
<id>attach-javadocs</id>
@@ -117,7 +124,7 @@
117124
<plugin>
118125
<groupId>org.apache.maven.plugins</groupId>
119126
<artifactId>maven-checkstyle-plugin</artifactId>
120-
<version>3.1.2</version>
127+
<version>3.6.0</version>
121128
<configuration>
122129
<configLocation>checkstyle.xml</configLocation>
123130
<propertyExpansion>basedir=${basedir}</propertyExpansion>
@@ -145,7 +152,7 @@
145152
<plugin>
146153
<groupId>org.codehaus.mojo</groupId>
147154
<artifactId>exec-maven-plugin</artifactId>
148-
<version>3.0.0</version>
155+
<version>3.5.1</version>
149156

150157
<configuration>
151158
<executable>java</executable>
@@ -165,15 +172,10 @@
165172
<plugin>
166173
<groupId>org.apache.maven.plugins</groupId>
167174
<artifactId>maven-compiler-plugin</artifactId>
168-
<version>3.8.1</version>
175+
<version>3.14.0</version>
169176
<configuration>
170-
<debug>true</debug>
171-
<debuglevel>none</debuglevel>
172-
<source>1.8</source>
173-
<target>1.8</target>
174-
<archive>
175-
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
176-
</archive>
177+
<debug>false</debug>
178+
<release>11</release>
177179
<compilerArgument>-Xlint:all</compilerArgument>
178180
<compilerArguments>
179181
<Werror />
@@ -183,21 +185,44 @@
183185
<plugin>
184186
<groupId>org.apache.maven.plugins</groupId>
185187
<artifactId>maven-site-plugin</artifactId>
186-
<version>3.9.1</version>
188+
<version>3.21.0</version>
187189
<configuration>
188190
</configuration>
189191
</plugin>
190-
<plugin>
191-
<groupId>org.apache.maven.plugins</groupId>
192-
<artifactId>maven-jar-plugin</artifactId>
193-
<configuration>
194-
<archive>
195-
<manifestEntries>
196-
<Automatic-Module-Name>com.grack.nanojson</Automatic-Module-Name>
197-
</manifestEntries>
198-
</archive>
199-
</configuration>
200-
</plugin>
192+
<plugin>
193+
<groupId>biz.aQute.bnd</groupId>
194+
<artifactId>bnd-maven-plugin</artifactId>
195+
<extensions>true</extensions>
196+
<executions>
197+
<execution>
198+
<id>jar</id>
199+
<goals>
200+
<goal>jar</goal>
201+
</goals>
202+
<configuration>
203+
<bnd><![CDATA[
204+
Bundle-SymbolicName: ${groupId}.${artifactId}
205+
Export-Package: com.grack.nanojson
206+
-jpms-module-info: com.grack.nanojson
207+
-noextraheaders:
208+
-removeheaders: \
209+
Tool, \
210+
Bnd-LastModified, \
211+
Bnd-ManifestVersion, \
212+
Build-Jdk, \
213+
Built-By, \
214+
Created-By, \
215+
Private-Package, \
216+
Bundle-DocURL, \
217+
Bundle-Name, \
218+
Bundle-Vendor,\
219+
Bundle-Description,\
220+
Bundle-SCM
221+
]]></bnd>
222+
</configuration>
223+
</execution>
224+
</executions>
225+
</plugin>
201226
</plugins>
202227
</build>
203228

@@ -210,7 +235,7 @@
210235
<plugin>
211236
<groupId>org.sonatype.plugins</groupId>
212237
<artifactId>nexus-staging-maven-plugin</artifactId>
213-
<version>1.6.8</version>
238+
<version>1.7.0</version>
214239
<extensions>true</extensions>
215240
<configuration>
216241
<serverId>sonatype-nexus-staging</serverId>
@@ -221,7 +246,7 @@
221246
<plugin>
222247
<groupId>org.apache.maven.plugins</groupId>
223248
<artifactId>maven-gpg-plugin</artifactId>
224-
<version>3.0.1</version>
249+
<version>3.2.8</version>
225250
<executions>
226251
<execution>
227252
<id>sign-artifacts</id>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2011 The nanojson Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.grack.nanojson;
17+
18+
import java.nio.CharBuffer;
19+
import java.util.PriorityQueue;
20+
import java.util.concurrent.atomic.AtomicInteger;
21+
22+
public final class CharBufferPool {
23+
24+
private static final AtomicInteger SIZE = new AtomicInteger(0);
25+
private static final int MAX_SIZE = 1000;
26+
private static final int MAX_RETAINED_BUFFER_SIZE = 16 * 1024; // 16KB limit for pooled buffers
27+
28+
private static final PriorityQueue<CharBuffer> BUFFERS = new PriorityQueue<>();
29+
30+
private CharBufferPool() {
31+
}
32+
33+
public static CharBuffer get(int capacity) {
34+
synchronized (BUFFERS) {
35+
if (!BUFFERS.isEmpty()) {
36+
CharBuffer buffer = BUFFERS.poll();
37+
if (buffer.capacity() < capacity) {
38+
return CharBuffer.allocate(capacity);
39+
}
40+
return buffer;
41+
}
42+
}
43+
44+
if (SIZE.incrementAndGet() > MAX_SIZE) {
45+
SIZE.decrementAndGet();
46+
throw new IllegalStateException("Buffer pool size limit exceeded");
47+
}
48+
49+
return CharBuffer.allocate(capacity);
50+
}
51+
52+
public static void release(CharBuffer buffer) {
53+
if (buffer == null || buffer.capacity() <= 0) {
54+
return;
55+
}
56+
57+
if (buffer.limit() > MAX_RETAINED_BUFFER_SIZE) {
58+
// If the buffer is too large, decrement SIZE so another can be created
59+
SIZE.decrementAndGet();
60+
return;
61+
}
62+
63+
buffer.clear();
64+
65+
synchronized (BUFFERS) {
66+
BUFFERS.add(buffer);
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)